class RakutenApi::Base::Model

Public Class Methods

casting() click to toggle source
# File lib/rakuten_api/base/model.rb, line 36
def casting
  {}
end
downcase(word) click to toggle source
# File lib/rakuten_api/base/model.rb, line 24
def downcase(word)
  _word = word.dup
  _word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  _word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  _word.downcase!
  _word
end
from_hash(hash) click to toggle source
# File lib/rakuten_api/base/model.rb, line 14
def from_hash(hash)
  obj = self.new
  hash.each_pair do |k, v|
    v = casting[k].call(v) if casting.include?(k)
    attribute = mapping.include?(k) ? mapping[k] : downcase(k)
    obj.send("#{attribute}=", v) if obj.respond_to?("#{attribute}=")
  end
  obj
end
mapping() click to toggle source
# File lib/rakuten_api/base/model.rb, line 32
def mapping
  {}
end

Public Instance Methods

to_hash() click to toggle source
# File lib/rakuten_api/base/model.rb, line 5
def to_hash
  {}.tap do |h|
    instance_variables.each do |sym|
      h[sym.to_s.sub('@', '').to_sym] = instance_variable_get(sym)
    end
  end
end