Class: KindleCG::Collections

Inherits:
Object
  • Object
show all
Defined in:
lib/KindleCG/collections.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollections

Returns a new instance of Collections.



5
6
7
# File 'lib/KindleCG/collections.rb', line 5

def initialize
  @collections = {}
end

Instance Attribute Details

#collectionsObject (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_jsonObject



19
20
21
# File 'lib/KindleCG/collections.rb', line 19

def to_json
  JSON.generate(@collections)
end