-
-
Save martinstannard/5596303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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