Class: FlickRaw::Response

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

Direct Known Subclasses

ResponseList

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h, type) ⇒ Response

:nodoc:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/flickraw/response.rb', line 16

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;" if Util.safe_for_eval?(k)
  }
  eval methods << "end"
end

Instance Attribute Details

#flickr_typeObject (readonly)

Returns the value of attribute flickr_type.



15
16
17
# File 'lib/flickraw/response.rb', line 15

def flickr_type
  @flickr_type
end

Class Method Details

.build(h, type) ⇒ Object

:nodoc:



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/flickraw/response.rb', line 3

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



29
# File 'lib/flickraw/response.rb', line 29

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

#inspectObject



31
# File 'lib/flickraw/response.rb', line 31

def inspect; @h.inspect end

#marshal_dumpObject



33
# File 'lib/flickraw/response.rb', line 33

def marshal_dump; [@h, @flickr_type] end

#marshal_load(data) ⇒ Object



34
# File 'lib/flickraw/response.rb', line 34

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

#to_hashObject



32
# File 'lib/flickraw/response.rb', line 32

def to_hash; @h end

#to_sObject



30
# File 'lib/flickraw/response.rb', line 30

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