class EventDb::EventReader::YamlParser

Public Class Methods

new( text ) click to toggle source
# File lib/eventdb/reader.rb, line 110
def initialize( text )
  @text = text
end
parse( text ) click to toggle source
# File lib/eventdb/reader.rb, line 105
def self.parse( text )  new( text ).parse; end

Public Instance Methods

parse() click to toggle source
# 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