Class: Firstfm::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/firstfm/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def artist
  @artist
end

#dateaddedObject

Returns the value of attribute dateadded.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def dateadded
  @dateadded
end

#formatObject

Returns the value of attribute format.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def format
  @format
end

#owner_nameObject

Returns the value of attribute owner_name.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def owner_name
  @owner_name
end

#owner_urlObject

Returns the value of attribute owner_url.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def owner_url
  @owner_url
end

#sizesObject

Returns the value of attribute sizes.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def sizes
  @sizes
end

#thumbsdownObject

Returns the value of attribute thumbsdown.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def thumbsdown
  @thumbsdown
end

#thumbsupObject

Returns the value of attribute thumbsup.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def thumbsup
  @thumbsup
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/firstfm/image.rb', line 5

def title
  @title
end

#urlObject

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

#originalObject



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