Skip to content

Instantly share code, notes, and snippets.

@martinstannard
Forked from kouky/gist:5596294
Created May 17, 2013 01:06
Show Gist options
  • Save martinstannard/5596303 to your computer and use it in GitHub Desktop.
Save martinstannard/5596303 to your computer and use it in GitHub Desktop.
# Get access to a Library object by locale, always scope by Locale
# A library object gives us conveneince methods to access
# books, authors, fiction and non-fiction book code indeicies by locale.
# The files that drive these indices are located in blake/data/models/db/library/[product]/[subject-index].yml
library = BlakeDataModels::Library.new(locale: 'au', name: 'reading_eggspress')
# What series are available in the locale's library?
library.series_names # Generates array ["abc", "blake_novels", "boffin_boy", "brainwaves", ...]
# What authors have books in this locale's library?
library.author_names # Generates array ["Alexander, Goldie", "Andersen, Hans Christian", "Anderson, WM", ...]
# Give me a list of book summaries for a particular book series?
# Generates an array of book summaries
# [ {"locale"=>"au", "series"=>"abc", "code"=>"abc_40_cool_science_tricks", "set"=>"the surfing scientist", "authors"=>["Meerman, Ruben"], "name"=>"40 Cool Science Tricks", ...}]
library.series('abc')
# Generate your collection of all book summaries for the entire locale
# This should generate an array of approx 1200 book summaries,
# use this to initialise your Ember data models
all_books = library.series_names.map { |series_code| library.series(series_code)}.flatten
# Filter all books by author
# This should generate an array of approx 200 book summaries
all_books.find_all {|book| book[:authors].include?("Pike, Katy") }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment