class SheetWrap::Row

Public Class Methods

new(worksheet, row_num) click to toggle source
# File lib/sheet_wrap/row.rb, line 3
def initialize(worksheet, row_num)
  @worksheet = worksheet
  @row_num = row_num
  @headers = worksheet.headers
  @getter_names = worksheet.headers.map(&:to_sym)
  @setter_names = worksheet.headers.map{|header| :"#{header}=" }
end

Public Instance Methods

method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/sheet_wrap/row.rb, line 11
def method_missing(name, *args)
  if (index = @getter_names.index(name))
    return @worksheet[@row_num, index + 1]
  elsif (index = @setter_names.index(name))
    return @worksheet[@row_num, index + 1] = args.first
  end
  super
end
save(args = {}) click to toggle source
# File lib/sheet_wrap/row.rb, line 20
def save(args = {})
  args.each do |key, value|
    self.send("#{key}=", value)
  end
  @worksheet.save
end
to_h() click to toggle source
# File lib/sheet_wrap/row.rb, line 27
def to_h
  @getter_names.each_with_object({}){|name, h| h[name] =  self.send(:"#{name}") }
end
Also aliased as: to_hash
to_hash()
Alias for: to_h