Class: ICS::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/ics/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Event

Returns a new instance of Event.



29
30
31
32
33
# File 'lib/ics/event.rb', line 29

def initialize(attributes = {})
  attributes.each do |key, val|
    send("#{key}=", val)
  end
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



7
8
9
# File 'lib/ics/event.rb', line 7

def action
  @action
end

#alarmuidObject

Returns the value of attribute alarmuid.



8
9
10
# File 'lib/ics/event.rb', line 8

def alarmuid
  @alarmuid
end

#attachObject

Returns the value of attribute attach.



9
10
11
# File 'lib/ics/event.rb', line 9

def attach
  @attach
end

#attendeeObject

Returns the value of attribute attendee.



10
11
12
# File 'lib/ics/event.rb', line 10

def attendee
  @attendee
end

#categoriesObject

Returns the value of attribute categories.



11
12
13
# File 'lib/ics/event.rb', line 11

def categories
  @categories
end

#createdObject

Returns the value of attribute created.



12
13
14
# File 'lib/ics/event.rb', line 12

def created
  @created
end

#descriptionObject

Returns the value of attribute description.



13
14
15
# File 'lib/ics/event.rb', line 13

def description
  @description
end

#dtendObject

Returns the value of attribute dtend.



14
15
16
# File 'lib/ics/event.rb', line 14

def dtend
  @dtend
end

#dtstampObject

Returns the value of attribute dtstamp.



15
16
17
# File 'lib/ics/event.rb', line 15

def dtstamp
  @dtstamp
end

#dtstartObject

Returns the value of attribute dtstart.



16
17
18
# File 'lib/ics/event.rb', line 16

def dtstart
  @dtstart
end

#last_modifiedObject

Returns the value of attribute last_modified.



17
18
19
# File 'lib/ics/event.rb', line 17

def last_modified
  @last_modified
end

#locationObject

Returns the value of attribute location.



18
19
20
# File 'lib/ics/event.rb', line 18

def location
  @location
end

#sequenceObject

Returns the value of attribute sequence.



19
20
21
# File 'lib/ics/event.rb', line 19

def sequence
  @sequence
end

#statusObject

Returns the value of attribute status.



20
21
22
# File 'lib/ics/event.rb', line 20

def status
  @status
end

#summaryObject

Returns the value of attribute summary.



21
22
23
# File 'lib/ics/event.rb', line 21

def summary
  @summary
end

#transpObject

Returns the value of attribute transp.



22
23
24
# File 'lib/ics/event.rb', line 22

def transp
  @transp
end

#triggerObject

Returns the value of attribute trigger.



23
24
25
# File 'lib/ics/event.rb', line 23

def trigger
  @trigger
end

#uidObject

Returns the value of attribute uid.



24
25
26
# File 'lib/ics/event.rb', line 24

def uid
  @uid
end

#urlObject

Returns the value of attribute url.



25
26
27
# File 'lib/ics/event.rb', line 25

def url
  @url
end

#x_apple_default_alarmObject

Returns the value of attribute x_apple_default_alarm.



26
27
28
# File 'lib/ics/event.rb', line 26

def x_apple_default_alarm
  @x_apple_default_alarm
end

#x_wr_alarmuidObject

Returns the value of attribute x_wr_alarmuid.



27
28
29
# File 'lib/ics/event.rb', line 27

def x_wr_alarmuid
  @x_wr_alarmuid
end

Class Method Details

.file(file) ⇒ Object

Given an exported ical file, parse it and create events.



38
39
40
41
42
43
44
45
46
# File 'lib/ics/event.rb', line 38

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.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ics/event.rb', line 49

def parse(str)
  chunks = chunk(str.split($/))
  attributes = chunks.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