Class: EventDb::EventReader::CsvParser

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/eventdb/reader.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ CsvParser

Returns a new instance of CsvParser.



70
71
72
# File 'lib/eventdb/reader.rb', line 70

def initialize( text )
  @text = text
end

Class Method Details

.parse(text) ⇒ Object



65
# File 'lib/eventdb/reader.rb', line 65

def self.parse( text )  new( text ).parse; end

Instance Method Details

#parseObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/eventdb/reader.rb', line 74

def parse
  events = []
  recs = CsvHash.parse( @text, :header_converters => :symbol )

  ## note:
  ##   support python's conferences.csv
  ##   subject     =>  name / title
  ##   website_url =>  url / link

  recs.each do |rec|
    title      = rec[:name]     || rec[:title] || rec[:subject]
    link       = rec[:url]      || rec[:link]  || rec[:website_url]
    place      = rec[:location] || rec[:place]

    start_date = Date.strptime( rec[:start] || rec[:start_date], '%Y-%m-%d' )
    end_date   = Date.strptime( rec[:end]   || rec[:end_date],   '%Y-%m-%d' )

    event = Event.new( title, link,
                       place,
                       start_date, end_date )
    ## pp event

    events << event
  end

  events
end