Class: IcalImporter::Parser
- Inherits:
-
Object
- Object
- IcalImporter::Parser
- Defined in:
- lib/ical_importer/parser.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
8
Instance Attribute Summary collapse
-
#bare_feed ⇒ Object
readonly
Returns the value of attribute bare_feed.
-
#feed ⇒ Object
readonly
Returns the value of attribute feed.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #all_events(&block) ⇒ Object
-
#initialize(url, options = {}) ⇒ Parser
constructor
Get a new Parser object.
- #parse(&block) ⇒ Object
- #recurrence_events(&block) ⇒ Object
- #should_parse? ⇒ Boolean
- #single_events(&block) ⇒ Object
- #worth_parsing? ⇒ Boolean
Constructor Details
#initialize(url, options = {}) ⇒ Parser
Get a new Parser object
url - URL where we download the ical feed options - Options hash
:timeout - Custom timeout for downloading ical feed [Default: 8]
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ical_importer/parser.rb', line 13 def initialize(url, ={}) @url = url @timeout = [:timeout] || DEFAULT_TIMEOUT @bare_feed = open_ical if should_parse? @bare_feed.pos = 0 begin @feed = Icalendar.parse @bare_feed rescue Exception => e # I know, I'm dirty, fix this to log to a config'd log end end @timezone = get_timezone @name = get_name end |
Instance Attribute Details
#bare_feed ⇒ Object (readonly)
Returns the value of attribute bare_feed.
3 4 5 |
# File 'lib/ical_importer/parser.rb', line 3 def @bare_feed end |
#feed ⇒ Object (readonly)
Returns the value of attribute feed.
3 4 5 |
# File 'lib/ical_importer/parser.rb', line 3 def feed @feed end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/ical_importer/parser.rb', line 3 def name @name end |
#timeout ⇒ Object
Returns the value of attribute timeout.
4 5 6 |
# File 'lib/ical_importer/parser.rb', line 4 def timeout @timeout end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
3 4 5 |
# File 'lib/ical_importer/parser.rb', line 3 def timezone @timezone end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/ical_importer/parser.rb', line 3 def url @url end |
Instance Method Details
#all_events(&block) ⇒ Object
37 38 39 |
# File 'lib/ical_importer/parser.rb', line 37 def all_events(&block) tap_and_each (@imported_single_events || []) + (@imported_recurrence_events || []), &block end |
#parse(&block) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/ical_importer/parser.rb', line 49 def parse(&block) if worth_parsing? collected = Collector.new(feed.first.events).collect @imported_single_events = collected.single_events @imported_recurrence_events = collected.recurrence_events tap_and_each (@imported_single_events + @imported_recurrence_events), &block end end |
#recurrence_events(&block) ⇒ Object
45 46 47 |
# File 'lib/ical_importer/parser.rb', line 45 def recurrence_events(&block) tap_and_each (@imported_recurrence_events || []), &block end |
#should_parse? ⇒ Boolean
29 30 31 |
# File 'lib/ical_importer/parser.rb', line 29 def should_parse? .present? end |
#single_events(&block) ⇒ Object
41 42 43 |
# File 'lib/ical_importer/parser.rb', line 41 def single_events(&block) tap_and_each (@imported_single_events || []), &block end |
#worth_parsing? ⇒ Boolean
33 34 35 |
# File 'lib/ical_importer/parser.rb', line 33 def worth_parsing? should_parse? && feed.present? && feed.first.present? end |