Method: Chop::Diff#hash_transformation
- Defined in:
- lib/chop/diff.rb
#hash_transformation(&block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chop/diff.rb', line 65 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 |