Class: GCal::Event

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

Constant Summary collapse

STATUS_REGEXP =
/http\:\/\/schemas\.google\.com\/g\/[0-9]+\#event\./

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#author_emailObject

Returns the value of attribute author_email.



4
5
6
# File 'lib/gcal/event.rb', line 4

def author_email
  @author_email
end

#author_nameObject

Returns the value of attribute author_name.



4
5
6
# File 'lib/gcal/event.rb', line 4

def author_name
  @author_name
end

#end_timeObject

Returns the value of attribute end_time.



4
5
6
# File 'lib/gcal/event.rb', line 4

def end_time
  @end_time
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/gcal/event.rb', line 4

def id
  @id
end

Returns the value of attribute link.



4
5
6
# File 'lib/gcal/event.rb', line 4

def link
  @link
end

#published_atObject

Returns the value of attribute published_at.



4
5
6
# File 'lib/gcal/event.rb', line 4

def published_at
  @published_at
end

#start_timeObject

Returns the value of attribute start_time.



4
5
6
# File 'lib/gcal/event.rb', line 4

def start_time
  @start_time
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/gcal/event.rb', line 4

def status
  @status
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/gcal/event.rb', line 4

def title
  @title
end

#updated_atObject

Returns the value of attribute updated_at.



4
5
6
# File 'lib/gcal/event.rb', line 4

def updated_at
  @updated_at
end

#whereObject

Returns the value of attribute where.



4
5
6
# File 'lib/gcal/event.rb', line 4

def where
  @where
end

#whoObject

Returns the value of attribute who.



4
5
6
# File 'lib/gcal/event.rb', line 4

def who
  @who
end

Class Method Details

.parse(calendar_id, entry) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gcal/event.rb', line 12

def parse(calendar_id, entry)
  parse_time = Time.respond_to?(:parse)
  event = self.new
  
  # common info
  event.id = entry['id'][0].gsub("http://www.google.com/calendar/feeds/#{calendar_id}/private/full/", '')
  event.title = entry['title'][0]['content']
  event.link = entry['link'][0]['href']
  event.status = entry['eventStatus'][0]['value'].gsub(Event::STATUS_REGEXP, '')
  event.where = entry['where'][0]['valueString']
  event.who = entry['who'][0]['valueString']
  
  # time info
  time = entry['when'][0]
  event.start_time = parse_time ? Time.parse(time['startTime']) : time['startTime']
  event.end_time = parse_time ? Time.parse(time['endTime']) : time['endTime']
  event.updated_at = parse_time ? Time.parse(entry['updated'][0]) : entry['updated'][0]
  event.published_at = parse_time ? Time.parse(entry['published'][0]) : entry['published'][0]
  
  # author
  author = entry['author'][0]
  event.author_name = author['name'] ? author['name'][0] : ''
  event.author_email = author['email'] ? author['email'][0] : ''
  event
end

.prepare_options(options) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gcal/event.rb', line 38

def prepare_options(options)
  options.symbolize_keys! if Hash.respond_to?(:symbolize_keys!)
  prepared_options = {}
  if options[:start_time]
    prepared_options['start-min'] = options[:start_time].strftime("%Y-%m-%dT%H:%M:%S")
  end
  if options[:end_time]
    prepared_options['start-max'] = options[:end_time].strftime("%Y-%m-%dT%H:%M:%S")
  end
  if options[:timezone]
    prepared_options['ctz'] = options[:timezone].gsub(' ', '_')
  end
  if prepared_options.size > 0 
    "?" + prepared_options.map{|k, v| "#{k}=#{v}" }.join('&')
  else
    ''
  end
end

Instance Method Details

#confirmed?Boolean

Returns:

  • (Boolean)


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

def confirmed?
  status == 'confirmed'
end