Class: KindleCG::Collections
- Inherits:
-
Object
- Object
- KindleCG::Collections
- Defined in:
- lib/KindleCG/collections.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
Instance Method Summary collapse
- #add(name, language = 'en-US') ⇒ Object
- #add_item_to_collection(collection_name, ebook) ⇒ Object
-
#initialize ⇒ Collections
constructor
A new instance of Collections.
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ Collections
Returns a new instance of Collections.
5 6 7 |
# File 'lib/KindleCG/collections.rb', line 5 def initialize @collections = {} end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
3 4 5 |
# File 'lib/KindleCG/collections.rb', line 3 def collections @collections end |
Instance Method Details
#add(name, language = 'en-US') ⇒ Object
9 10 11 12 13 |
# File 'lib/KindleCG/collections.rb', line 9 def add(name, language = 'en-US') collection_name = "#{name}@#{language}" @collections[collection_name] = { items: [] } collection_name end |
#add_item_to_collection(collection_name, ebook) ⇒ Object
15 16 17 |
# File 'lib/KindleCG/collections.rb', line 15 def add_item_to_collection(collection_name, ebook) @collections[collection_name][:items] << ebook.hash end |
#to_json ⇒ Object
19 20 21 |
# File 'lib/KindleCG/collections.rb', line 19 def to_json JSON.generate(@collections) end |