Class: ICS::Event
- Inherits:
-
Object
- Object
- ICS::Event
- Defined in:
- lib/ics/event.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#alarmuid ⇒ Object
Returns the value of attribute alarmuid.
-
#attach ⇒ Object
Returns the value of attribute attach.
-
#created ⇒ Object
Returns the value of attribute created.
-
#description ⇒ Object
Returns the value of attribute description.
-
#dtend ⇒ Object
Returns the value of attribute dtend.
-
#dtstamp ⇒ Object
Returns the value of attribute dtstamp.
-
#dtstart ⇒ Object
Returns the value of attribute dtstart.
-
#location ⇒ Object
Returns the value of attribute location.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#status ⇒ Object
Returns the value of attribute status.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#transp ⇒ Object
Returns the value of attribute transp.
-
#trigger ⇒ Object
Returns the value of attribute trigger.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#url ⇒ Object
Returns the value of attribute url.
-
#x_wr_alarmuid ⇒ Object
Returns the value of attribute x_wr_alarmuid.
Class Method Summary collapse
-
.file(file) ⇒ Object
Given an exported ical file, parse it and create events.
-
.parse(str) ⇒ Object
Parse data and return new Event.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(attributes = {}) ⇒ Event
Returns a new instance of Event.
25 26 27 28 29 |
# File 'lib/ics/event.rb', line 25 def initialize(attributes = {}) attributes.each do |key, val| send("#{key}=", val) end end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
7 8 9 |
# File 'lib/ics/event.rb', line 7 def action @action end |
#alarmuid ⇒ Object
Returns the value of attribute alarmuid.
8 9 10 |
# File 'lib/ics/event.rb', line 8 def alarmuid @alarmuid end |
#attach ⇒ Object
Returns the value of attribute attach.
9 10 11 |
# File 'lib/ics/event.rb', line 9 def attach @attach end |
#created ⇒ Object
Returns the value of attribute created.
10 11 12 |
# File 'lib/ics/event.rb', line 10 def created @created end |
#description ⇒ Object
Returns the value of attribute description.
11 12 13 |
# File 'lib/ics/event.rb', line 11 def description @description end |
#dtend ⇒ Object
Returns the value of attribute dtend.
12 13 14 |
# File 'lib/ics/event.rb', line 12 def dtend @dtend end |
#dtstamp ⇒ Object
Returns the value of attribute dtstamp.
13 14 15 |
# File 'lib/ics/event.rb', line 13 def dtstamp @dtstamp end |
#dtstart ⇒ Object
Returns the value of attribute dtstart.
14 15 16 |
# File 'lib/ics/event.rb', line 14 def dtstart @dtstart end |
#location ⇒ Object
Returns the value of attribute location.
15 16 17 |
# File 'lib/ics/event.rb', line 15 def location @location end |
#sequence ⇒ Object
Returns the value of attribute sequence.
16 17 18 |
# File 'lib/ics/event.rb', line 16 def sequence @sequence end |
#status ⇒ Object
Returns the value of attribute status.
17 18 19 |
# File 'lib/ics/event.rb', line 17 def status @status end |
#summary ⇒ Object
Returns the value of attribute summary.
18 19 20 |
# File 'lib/ics/event.rb', line 18 def summary @summary end |
#transp ⇒ Object
Returns the value of attribute transp.
19 20 21 |
# File 'lib/ics/event.rb', line 19 def transp @transp end |
#trigger ⇒ Object
Returns the value of attribute trigger.
20 21 22 |
# File 'lib/ics/event.rb', line 20 def trigger @trigger end |
#uid ⇒ Object
Returns the value of attribute uid.
21 22 23 |
# File 'lib/ics/event.rb', line 21 def uid @uid end |
#url ⇒ Object
Returns the value of attribute url.
22 23 24 |
# File 'lib/ics/event.rb', line 22 def url @url end |
#x_wr_alarmuid ⇒ Object
Returns the value of attribute x_wr_alarmuid.
23 24 25 |
# File 'lib/ics/event.rb', line 23 def x_wr_alarmuid @x_wr_alarmuid end |
Class Method Details
.file(file) ⇒ Object
Given an exported ical file, parse it and create events.
34 35 36 37 38 39 40 41 42 |
# File 'lib/ics/event.rb', line 34 def file(file) # format line endings. content = file.readlines.map(&:chomp).join($/) line_ending = $/ content.split("BEGIN:VEVENT#{line_ending}")[1..-1].map do |data_string| data_string = data_string.split("END:VEVENT#{line_ending}").first parse(data_string) end end |
.parse(str) ⇒ Object
Parse data and return new Event.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ics/event.rb', line 45 def parse(str) attributes = str.split($/).inject({}) do |hash, line| key, value = line.split(':', 2) next hash if key =~ /^BEGIN$|^END$/ # Ignore any other book ends. value = value.chomp if value key = key. split(';', 2). first. # Ignore extra data other than just the name of the attribute. gsub('-', '_') # underscore. hash[key.downcase.to_sym] = value hash end new(attributes) end |