Sha256: 7cf9a2650ff6a6ce2e33ab2d5175b672d96cd2ed0a572ed84c2912da3c9c0fff

Contents?: true

Size: 618 Bytes

Versions: 2

Compression:

Stored size: 618 Bytes

Contents

require_relative 'flex_data'

module FlexData

  class Spreadsheet

    def map_to_h (first = 1, last = -1)
      (first..last).inject([]) { |acc, index|
        acc << row_to_h(index)
      }
    end

    def map_to_ostruct (first = 1, last = -1)
      (first..last).inject([]) { |acc, index|
        acc << row_to_ostruct(index)
      }
    end

    def row_to_h (index)
      keys = @sheet[0]
      output = {}
      @sheet[index].each_with_index { |value, i|
        output.store(keys[i], value)
      }
      output
    end

    def row_to_ostruct (index)
      OpenStruct.new(row_to_h(index))
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flex_data-0.1.2 lib/flex_data/spreadsheet/open_struct.rb
flex_data-0.1.1 lib/flex_data/spreadsheet/open_struct.rb