class Footstats::Resource
Public Class Methods
field(internal_key, external_key)
click to toggle source
# File lib/footstats/resource.rb, line 17 def self.field(internal_key, external_key) attr_accessor internal_key fields[external_key] = internal_key unless fields.include? external_key end
fields()
click to toggle source
# File lib/footstats/resource.rb, line 13 def self.fields @fields ||= {} end
new(attributes={})
click to toggle source
# File lib/footstats/resource.rb, line 5 def initialize(attributes={}) attributes.each do |attr_name, value| if self.class.fields.include? attr_name.to_sym send("#{self.class.fields[attr_name.to_sym]}=", value) end end end
Public Instance Methods
to_hash()
click to toggle source
# File lib/footstats/resource.rb, line 22 def to_hash hash = Hash.new self.class.fields.values.collect do |key| hash[key] = self.send(key) end hash end
to_json(*params)
click to toggle source
# File lib/footstats/resource.rb, line 30 def to_json(*params) self.to_hash.to_json end