Class: Calagator::Source::Parser
- Inherits:
-
Struct
- Object
- Struct
- Calagator::Source::Parser
- Defined in:
- app/models/calagator/source/parser/http_authentication_required_error.rb,
app/models/calagator/source/parser.rb,
app/models/calagator/source/parser/not_found.rb
Overview
Exception raised if user requests parsing of a URL that requires authentication but none was provided.
Defined Under Namespace
Classes: Hcal, HttpAuthenticationRequiredError, Ical, NotFound
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .<=>(other) ⇒ Object
- .inherited(subclass) ⇒ Object
-
.labels ⇒ Object
Returns an Array of sorted string labels for the parsers.
- .read_url(url) ⇒ Object
-
.to_events(url: nil, source: nil) ⇒ Object
Return an Array of unsaved Event instances.
Instance Method Summary collapse
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source
13 14 15 |
# File 'app/models/calagator/source/parser.rb', line 13 def source @source end |
#url ⇒ Object
Returns the value of attribute url
13 14 15 |
# File 'app/models/calagator/source/parser.rb', line 13 def url @url end |
Class Method Details
.<=>(other) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/calagator/source/parser.rb', line 56 def self.<=>(other) # use site-specific parsers first, then generics alphabetically if url_pattern && !other.url_pattern -1 elsif !url_pattern && other.url_pattern 1 else label <=> other.label end end |
.inherited(subclass) ⇒ Object
35 36 37 |
# File 'app/models/calagator/source/parser.rb', line 35 def self.inherited(subclass) parsers << subclass end |
.labels ⇒ Object
Returns an Array of sorted string labels for the parsers.
42 43 44 |
# File 'app/models/calagator/source/parser.rb', line 42 def self.labels parsers.map { |p| p.label.to_s }.sort_by(&:downcase) end |
.read_url(url) ⇒ Object
46 47 48 49 50 |
# File 'app/models/calagator/source/parser.rb', line 46 def self.read_url(url) RestClient.get(url).to_str rescue RestClient::Unauthorized raise Source::Parser::HttpAuthenticationRequiredError end |
.to_events(url: nil, source: nil) ⇒ Object
Return an Array of unsaved Event instances.
15 16 17 18 19 20 21 22 |
# File 'app/models/calagator/source/parser.rb', line 15 def self.to_events(url: nil, source: nil) # Return events from the first parser that succeeds events = matched_parsers(url).lazy.collect do |parser| parser.new(url, source).to_events end.detect(&:present?) events || [] end |
Instance Method Details
#to_events ⇒ Object
52 53 54 |
# File 'app/models/calagator/source/parser.rb', line 52 def to_events raise NotImplementedError end |