Method: Chop::Diff#hash_transformation
- Defined in:
- lib/chop/diff.rb
#hash_transformation(&block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chop/diff.rb', line 79 def hash_transformation &block transformation do |rows| header = rows[0] keys = header.to_a.map.with_index do |cell, index| key = cell.text.parameterize.underscore next key if key.present? next cell.text if cell.text.present? index + 1 end body = rows[1..-1] hashes = body.map { |row| HashWithIndifferentAccess[keys.zip(row)] } yield hashes [header] + hashes.map(&:values) end end |