Class: Flickr::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr/attributes.rb

Overview

This class stores the information about attributes. It stores the name, locations and type, and it is responsible for retrieving the attribute values from Flickr’s JSON response, and optionally coercing them to the right type (for example, time can be represented in JSON only as a string, and here we convert it to actual instance of Ruby’s ‘Time` class).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Attribute



60
61
62
63
# File 'lib/flickr/attributes.rb', line 60

def initialize(name, type)
  @name, @type = name, type
  @locations = []
end

Instance Attribute Details

#locationsObject (readonly)

Returns the value of attribute locations.



58
59
60
# File 'lib/flickr/attributes.rb', line 58

def locations
  @locations
end

#nameObject (readonly)

Returns the value of attribute name.



58
59
60
# File 'lib/flickr/attributes.rb', line 58

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



58
59
60
# File 'lib/flickr/attributes.rb', line 58

def type
  @type
end

Instance Method Details

#add_locations(locations) ⇒ Object



65
66
67
# File 'lib/flickr/attributes.rb', line 65

def add_locations(locations)
  @locations = locations + @locations
end

#value(object) ⇒ Object



69
70
71
72
# File 'lib/flickr/attributes.rb', line 69

def value(object)
  value = find_value(object)
  coerce(value, object, @type)
end