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:



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/flickraw.rb', line 63

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.



62
63
64
# File 'lib/flickraw.rb', line 62

def flickr_type
  @flickr_type
end

Class Method Details

.build(h, type) ⇒ Object

:nodoc:



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/flickraw.rb', line 50

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



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

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

#inspectObject



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

def inspect; @h.inspect end

#marshal_dumpObject



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

def marshal_dump; [@h, @flickr_type] end

#marshal_load(data) ⇒ Object



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

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

#to_hashObject



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

def to_hash; @h end

#to_sObject



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

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