Class: Flickr::Attribute
- Inherits:
-
Object
- Object
- Flickr::Attribute
- 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
-
#locations ⇒ Object
readonly
Returns the value of attribute locations.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #add_locations(locations) ⇒ Object
-
#initialize(name, type) ⇒ Attribute
constructor
A new instance of Attribute.
- #value(object) ⇒ Object
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
#locations ⇒ Object (readonly)
Returns the value of attribute locations.
58 59 60 |
# File 'lib/flickr/attributes.rb', line 58 def locations @locations end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
58 59 60 |
# File 'lib/flickr/attributes.rb', line 58 def name @name end |
#type ⇒ Object (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 |