Class: EventDb::EventReader::YamlParser

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) ⇒ YamlParser

Returns a new instance of YamlParser.



110
111
112
# File 'lib/eventdb/reader.rb', line 110

def initialize( text )
  @text = text
end

Class Method Details

.parse(text) ⇒ Object



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

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

Instance Method Details

#parseObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/eventdb/reader.rb', line 114

def parse
  events = []
  ## fix:  unquoted dates e.g. 2022-11-27  no longer supported!!
  ##         with YAML.safe_load
  ##
  ## quick fix:  assume Pysch yaml parser
  ##   and allow Date!!!
  recs = YAML.load( @text, permitted_classes: [Date] )

  recs.each do |rec|
    title      = rec['name']     || rec['title']
    link       = rec['url']      || rec['link']
    place      = rec['location'] || rec['place']

    # note: already parsed into a date (NOT string) by yaml parser!!
    start_date = rec['start']    || rec['start_date']
    end_date   = rec['end']      || rec['end_date']

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

    events << event
  end

  events
end