Class: Flickr::Response
- Inherits:
-
Object
- Object
- Flickr::Response
- Defined in:
- lib/flickr/response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#flickr_type ⇒ Object
readonly
Returns the value of attribute flickr_type.
Class Method Summary collapse
-
.build(h, type) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #[](k) ⇒ Object
-
#initialize(h, type) ⇒ Response
constructor
:nodoc:.
- #inspect ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(data) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(h, type) ⇒ Response
:nodoc:
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flickr/response.rb', line 18 def initialize(h, type) # :nodoc: @flickr_type, @h = type, {} methods = 'class << self;' h.each do |k, v| @h[k] = case v when Hash Response.build(v, k) when Array v.all? { |e| String === e } ? v : v.map { |e| Response.build(e, k) } else v end methods << "def #{k}; @h['#{k}'] end;" if Util.safe_for_eval?(k) end eval methods << 'end' end |
Instance Attribute Details
#flickr_type ⇒ Object (readonly)
Returns the value of attribute flickr_type.
4 5 6 |
# File 'lib/flickr/response.rb', line 4 def flickr_type @flickr_type end |
Class Method Details
.build(h, type) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/flickr/response.rb', line 6 def self.build(h, type) # :nodoc: if h.is_a? Response h elsif type =~ /s$/ and (a = h[$`]).is_a? Array ResponseList.new(h, type, a.map { |e| Response.build(e, $`) }) elsif h.keys == ['_content'] h['_content'] else Response.new(h, type) end end |
Instance Method Details
#[](k) ⇒ Object
33 |
# File 'lib/flickr/response.rb', line 33 def [](k); @h[k] end |
#inspect ⇒ Object
35 |
# File 'lib/flickr/response.rb', line 35 def inspect; @h.inspect end |
#marshal_dump ⇒ Object
37 |
# File 'lib/flickr/response.rb', line 37 def marshal_dump; [@h, @flickr_type] end |
#marshal_load(data) ⇒ Object
38 |
# File 'lib/flickr/response.rb', line 38 def marshal_load(data); initialize(*data) end |
#to_hash ⇒ Object
36 |
# File 'lib/flickr/response.rb', line 36 def to_hash; @h end |
#to_s ⇒ Object
34 |
# File 'lib/flickr/response.rb', line 34 def to_s; @h['_content'] || super end |