app/models/calagator/source/parser.rb in calagator-1.0.0.rc2 vs app/models/calagator/source/parser.rb in calagator-1.0.0.rc3
- old
+ new
@@ -7,20 +7,16 @@
# A hierarchy of classes that provide a way to parse different source formats and return hCalendar events.
# The base class for all format-specific parsers. Do not use instances of this class
# directly, use a subclass of Parser to do the parsing instead.
module Calagator
-class Source::Parser < Struct.new(:opts)
+class Source::Parser < Struct.new(:url, :source)
# Return an Array of unsaved Event instances.
- #
- # Options: (these vary between specific parsers)
- # * :url - URL string to read as parser input.
- # * :content - String to read as parser input.
- def self.to_events(opts)
+ def self.to_events(url: nil, source: nil)
# Return events from the first parser that suceeds
- events = matched_parsers(opts[:url]).lazy.collect { |parser|
- parser.new(opts).to_events
+ events = matched_parsers(url).lazy.collect { |parser|
+ parser.new(url, source).to_events
}.detect(&:present?)
events || []
end
@@ -81,13 +77,12 @@
def venue_or_duplicate(venue)
duplicates = venue.find_exact_duplicates
if duplicates.present?
duplicates.first.progenitor
else
- venue_machine_tag_name = venue.tag_list.find { |t|
- # Match 2 in the MACHINE_TAG_PATTERN is the predicate
- ActsAsTaggableOn::Tag::VENUE_PREDICATES.include? t.match(ActsAsTaggableOn::Tag::MACHINE_TAG_PATTERN)[2]
- }
+ venue_machine_tag_name = venue.tag_list.find do |tag_name|
+ MachineTag.new(tag_name).venue?
+ end
matched_venue = Venue.tagged_with(venue_machine_tag_name).first
if matched_venue.present?
matched_venue.progenitor
else