Class: Firstfm::Image
- Inherits:
-
Object
- Object
- Firstfm::Image
- Defined in:
- lib/firstfm/image.rb
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#dateadded ⇒ Object
Returns the value of attribute dateadded.
-
#format ⇒ Object
Returns the value of attribute format.
-
#owner_name ⇒ Object
Returns the value of attribute owner_name.
-
#owner_url ⇒ Object
Returns the value of attribute owner_url.
-
#sizes ⇒ Object
Returns the value of attribute sizes.
-
#thumbsdown ⇒ Object
Returns the value of attribute thumbsdown.
-
#thumbsup ⇒ Object
Returns the value of attribute thumbsup.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#artist ⇒ Object
Returns the value of attribute artist.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def artist @artist end |
#dateadded ⇒ Object
Returns the value of attribute dateadded.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def dateadded @dateadded end |
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def format @format end |
#owner_name ⇒ Object
Returns the value of attribute owner_name.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def owner_name @owner_name end |
#owner_url ⇒ Object
Returns the value of attribute owner_url.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def owner_url @owner_url end |
#sizes ⇒ Object
Returns the value of attribute sizes.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def sizes @sizes end |
#thumbsdown ⇒ Object
Returns the value of attribute thumbsdown.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def thumbsdown @thumbsdown end |
#thumbsup ⇒ Object
Returns the value of attribute thumbsup.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def thumbsup @thumbsup end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/firstfm/image.rb', line 5 def url @url end |
Class Method Details
.init_from_array(array) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/firstfm/image.rb', line 7 def self.init_from_array(array) return [] unless array.is_a?(Array) array.inject([]) do |arr, image| arr << init_from_hash(image) arr end end |
.init_from_hash(hash) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/firstfm/image.rb', line 15 def self.init_from_hash(hash) return nil unless hash.is_a?(Hash) Image.new.tap do |image| image.title = hash["title"] image.url = hash["url"] image.dateadded = Chronic.parse(hash["dateadded"]) image.format = hash["format"] image.sizes = hash["sizes"]["size"] end end |
Instance Method Details
#original ⇒ Object
26 27 28 |
# File 'lib/firstfm/image.rb', line 26 def original self.sizes.detect {|s| s.attributes["name"] == "original"} end |
#with_width(width) ⇒ Object
30 31 32 |
# File 'lib/firstfm/image.rb', line 30 def with_width(width) self.sizes.detect {|s| s.attributes["width"].to_i >= width} end |