class Firstfm::Image

Attributes

artist[RW]
dateadded[RW]
format[RW]
owner_name[RW]
owner_url[RW]
sizes[RW]
thumbsdown[RW]
thumbsup[RW]
title[RW]
url[RW]

Public Class Methods

init_from_array(array) click to toggle source
# 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) click to toggle source
# 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

Public Instance Methods

original() click to toggle source
# File lib/firstfm/image.rb, line 26
def original
  self.sizes.detect {|s| s.attributes["name"] == "original"}
end
with_width(width) click to toggle source
# File lib/firstfm/image.rb, line 30
def with_width(width)
  self.sizes.detect {|s| s.attributes["width"].to_i >= width}
end