class Paid::APIList
Attributes
data[R]
klass[R]
Public Class Methods
new(klass, json={}, api_method=nil)
click to toggle source
# File lib/paid/api_list.rb, line 8 def initialize(klass, json={}, api_method=nil) if klass.is_a?(Class) @klass = klass else @klass = Util.constantize(klass) end refresh_from(json) end
Public Instance Methods
[](k)
click to toggle source
# File lib/paid/api_list.rb, line 45 def [](k) data[k] end
[]=(k, v)
click to toggle source
# File lib/paid/api_list.rb, line 49 def []=(k, v) data[k]=v end
each(&blk)
click to toggle source
# File lib/paid/api_list.rb, line 61 def each(&blk) data.each(&blk) end
inspect()
click to toggle source
# File lib/paid/api_list.rb, line 65 def inspect "#<#{self.class}[#{@klass}]:0x#{self.object_id.to_s(16)}> Data: " + JSON.pretty_generate(inspect_data) end
inspect_data()
click to toggle source
# File lib/paid/api_list.rb, line 69 def inspect_data ret = [] data.each do |d| if d.respond_to?(:inspect_nested) ret << d.inspect_nested else ret << d end end ret end
last()
click to toggle source
# File lib/paid/api_list.rb, line 53 def last data.last end
length()
click to toggle source
# File lib/paid/api_list.rb, line 57 def length data.length end
refresh_from(json, api_method=nil)
click to toggle source
# File lib/paid/api_list.rb, line 18 def refresh_from(json, api_method=nil) unless json.is_a?(Hash) json = { :data => json } end json = Util.symbolize_keys(json) clear_api_attributes @api_method = api_method @data = [] @json = Util.sorta_deep_clone(json) json.each do |k, v| if k.to_sym == :data if v.respond_to?(:map) instance_variable_set("@#{k}", v.map{ |i| @klass.new(i) }) else instance_variable_set("@#{k}", v || []) end elsif self.class.api_attribute_names.include?(k) instance_variable_set("@#{k}", determine_api_attribute_value(k, v)) end end self end