Sha256: 28ca90035cbe0d7b0e622df5389566e64fa62ab5767f7f9e183c6071c51f44fa
Contents?: true
Size: 1.06 KB
Versions: 4
Compression:
Stored size: 1.06 KB
Contents
module Apress module YandexMarket module Presenters class Base class << self attr_accessor :attributes attributes = [] end def initialize @counter = 0 end def expose(row) record = { __line__: @counter += 1, __column__: 1 } record.merge! filter(row) record end private def filter(row, attrs = self.class.attributes) attrs.each_with_object({}) do |key, result| if key.is_a? Hash key.each do |hash_key, hash_attrs| next unless row.key? hash_key result[hash_key] = if row[hash_key].is_a? Array row[hash_key].map { |item| filter(item, hash_attrs) } else filter(row[hash_key], hash_attrs) end end elsif row.key? key result[key] = row[key] end end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems