Class: FlickRaw::Response

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

Direct Known Subclasses

ResponseList

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h, type) ⇒ Response

:nodoc:



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/flickraw.rb', line 174

def initialize(h, type) # :nodoc:
  @flickr_type, @h = type, {}
  methods = "class << self;"
  h.each {|k,v|
    @h[k] = case v
      when Hash  then Response.build(v, k)
      when Array then v.collect {|e| Response.build(e, k)}
      else v
    end
    methods << "def #{k}; @h['#{k}'] end;"
  }
  eval methods << "end"
end

Instance Attribute Details

#flickr_typeObject (readonly)

Returns the value of attribute flickr_type.



173
174
175
# File 'lib/flickraw.rb', line 173

def flickr_type
  @flickr_type
end

Class Method Details

.build(h, type) ⇒ Object

:nodoc:



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/flickraw.rb', line 161

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.collect {|e| Response.build(e, $`)})
  elsif h.keys == ["_content"]
    h["_content"]
  else
    Response.new(h, type)
  end
end

Instance Method Details

#[](k) ⇒ Object



187
# File 'lib/flickraw.rb', line 187

def [](k); @h[k] end

#inspectObject



189
# File 'lib/flickraw.rb', line 189

def inspect; @h.inspect end

#marshal_dumpObject



191
# File 'lib/flickraw.rb', line 191

def marshal_dump; [@h, @flickr_type] end

#marshal_load(data) ⇒ Object



192
# File 'lib/flickraw.rb', line 192

def marshal_load(data); initialize(*data) end

#to_hashObject



190
# File 'lib/flickraw.rb', line 190

def to_hash; @h end

#to_sObject



188
# File 'lib/flickraw.rb', line 188

def to_s; @h["_content"] || super end