Class: Rdio::JSONObj

Inherits:
Object show all
Defined in:
lib/rdio/base.rb

Overview


An Object that is based on json with simple types


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ JSONObj

Returns a new instance of JSONObj.



208
209
210
# File 'lib/rdio/base.rb', line 208

def initialize(json)
  @json = json
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, args = {}) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/rdio/base.rb', line 212

def method_missing(method,args={})
  meth = method.to_s
  res = @json[meth]
  #
  # Maybe this should be a number
  #
  if meth =~ /_count$/ or meth =~ /^num_/
    begin
      return res.to_i
    rescue Exception => e
      STDERR.puts "#{meth} (err) #{e}"
    end
  end
  return res
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



206
207
208
# File 'lib/rdio/base.rb', line 206

def json
  @json
end