class FastshopCatalog::BaseEntity
Public Class Methods
translate(map)
click to toggle source
# File lib/fastshop_catalog/base_entity.rb, line 4 def self.translate(map) #instantiates the translation map and creates accessors @translate_map = map self.instance_eval do map.each_key{|k| attr_accessor k} end end
translate_symbol(symbol)
click to toggle source
# File lib/fastshop_catalog/base_entity.rb, line 12 def self.translate_symbol(symbol) @translate_map[symbol] end
Public Instance Methods
to_json(*a)
click to toggle source
# File lib/fastshop_catalog/base_entity.rb, line 31 def to_json(*a) to_map.to_json(*a) end
to_map()
click to toggle source
# File lib/fastshop_catalog/base_entity.rb, line 16 def to_map map = {} #translates the variables to it's synonyms self.class.public_instance_methods(optional=false).grep(/.*[^\=]$/).each do |m| map[self.class.translate_symbol(m.to_sym)] = self.send(m) if self.send(m) end #orders the map by the synonym map.keys.sort.inject({}) do |o, k| content = map[k] content = content.to_map if content.respond_to? :to_map o[k] = content o end end