Class: TimelineSetter::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/timeline_setter/parser.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Parser) initialize(sheet)

Initialize a new timeline from a CSV file via TableFu, add a hash for each row (event) in the sheet to an events array. Sheet should contain columns for

* date
* display_date
* description
* link
* thumbnail
* series
* html


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/timeline_setter/parser.rb', line 16

def initialize(sheet)
  @events = []
  spreadsheet = TableFu.new(sheet) do |s|
    s.columns = %w[date display_date description link series html]
  end

  spreadsheet.rows.each do |row|
    hash = spreadsheet.columns.inject({}) {|memo, column| memo[column.to_sym] = row[column].to_s ; memo}
    @events << hash
  end
end

Instance Attribute Details

- (Object) events (readonly)

Returns the value of attribute events



3
4
5
# File 'lib/timeline_setter/parser.rb', line 3

def events
  @events
end