Class: Haecksler::Sheet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/haecksler/sheet.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{ header: false, footer: false, header_check: proc{ false }, footer_check: proc{ false } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, options = {}) ⇒ Sheet

Returns a new instance of Sheet.



9
10
11
12
13
14
15
16
17
# File 'lib/haecksler/sheet.rb', line 9

def initialize(input, options={})
  options = DEFAULT_OPTIONS.merge(options)
  @header = options[:header]
  @footer = options[:footer]
  @row    = options[:row]
  @input  = input
  @header_check = options[:header_check]
  @footer_check = options[:footer_check]
end

Instance Attribute Details

#rowObject (readonly)

Returns the value of attribute row.



5
6
7
# File 'lib/haecksler/sheet.rb', line 5

def row
  @row
end

Instance Method Details

#eachObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/haecksler/sheet.rb', line 19

def each
  @input.lazy.each do |input|
    if @header_check.call(input)
      yield @header.parse(input.chomp)
    elsif @footer_check.call(input)
      yield @footer.parse(input.chomp)
    else
      yield @row.parse(input.chomp)
    end
  end
end