Class: Epubify::Item
- Inherits:
-
Object
- Object
- Epubify::Item
- Defined in:
- lib/shelf/item.rb
Instance Attribute Summary collapse
-
#cover_url ⇒ Object
Returns the value of attribute cover_url.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#issued ⇒ Object
Returns the value of attribute issued.
-
#language ⇒ Object
Returns the value of attribute language.
-
#periodical_id ⇒ Object
Returns the value of attribute periodical_id.
-
#periodical_token ⇒ Object
Returns the value of attribute periodical_token.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
- #downloads ⇒ Object
- #from_hash(h) ⇒ Object
-
#initialize(hash = nil) {|_self| ... } ⇒ Item
constructor
A new instance of Item.
- #save ⇒ Object
- #share(item_id) ⇒ Object
Constructor Details
#initialize(hash = nil) {|_self| ... } ⇒ Item
Returns a new instance of Item.
9 10 11 12 13 14 15 16 17 |
# File 'lib/shelf/item.rb', line 9 def initialize hash = nil, &block summary = "" description = "" language = "no" issued = "#{Date.today.to_s}" from_hash hash if hash yield self if block end |
Instance Attribute Details
#cover_url ⇒ Object
Returns the value of attribute cover_url.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def cover_url @cover_url end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def id @id end |
#issued ⇒ Object
Returns the value of attribute issued.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def issued @issued end |
#language ⇒ Object
Returns the value of attribute language.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def language @language end |
#periodical_id ⇒ Object
Returns the value of attribute periodical_id.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def periodical_id @periodical_id end |
#periodical_token ⇒ Object
Returns the value of attribute periodical_token.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def periodical_token @periodical_token end |
#summary ⇒ Object
Returns the value of attribute summary.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def summary @summary end |
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def thumbnail_url @thumbnail_url end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/shelf/item.rb', line 7 def title @title end |
Class Method Details
.find(id) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/shelf/item.rb', line 19 def self.find id res = ShelfApi.item(id) item = res["item"] Item.new do |i| i.from_hash item end end |
Instance Method Details
#destroy ⇒ Object
52 53 54 |
# File 'lib/shelf/item.rb', line 52 def destroy ShelfApi.destroy_item(id) if id end |
#downloads ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/shelf/item.rb', line 61 def downloads res = ShelfApi.downloads(id) d = [] res["downloads"].each do |hash| d << Download.new(hash) end d end |
#from_hash(h) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/shelf/item.rb', line 28 def from_hash h self.id = h["id"] self.periodical_id = h["periodical_id"] self.title = h["title"] self.summary = h["summary"] self.description = h["description"] self.cover_url = h["cover_url"] self.thumbnail_url = h["thumbnail_url"] self.language = h["language"] self.issued = h["issued"] end |
#save ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/shelf/item.rb', line 40 def save @query = { :item => { :periodical_token => periodical_token, :title => title, :summary => summary, :description => description, :cover_url => cover_url, :thumbnail_url => thumbnail_url, :language => language, :issued => issued } } if id res = ShelfApi.update_item(id, @query) else res = ShelfApi.create_item(@query) from_hash res["item"] end res end |
#share(item_id) ⇒ Object
56 57 58 59 |
# File 'lib/shelf/item.rb', line 56 def share item_id @query = { :shelf_item => { :shelf_id => nil, :item_id => item_id } } ShelfApi.share_item(@query) end |