Class: Gaah::Calendar::Who

Inherits:
Object
  • Object
show all
Defined in:
lib/gaah/calendar/who.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Who

Returns a new instance of Who.



5
6
7
8
9
# File 'lib/gaah/calendar/who.rb', line 5

def initialize(json)
  @name  = json['displayName'].to_s
  @email = json['email'].to_s
  @resource = !!json['resource']
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/gaah/calendar/who.rb', line 4

def email
  @email
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/gaah/calendar/who.rb', line 4

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/gaah/calendar/who.rb', line 4

def resource
  @resource
end

Class Method Details

.batch_process(xml, exclude_catch_all_user = true) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/gaah/calendar/who.rb', line 38

def self.batch_process(xml, exclude_catch_all_user = true)
  (xml/:entry).map do |entry|
    who = new(entry)
    if exclude_catch_all_user && who.catch_all_user?
      nil
    else
      who
    end
  end.compact
end

Instance Method Details

#catch_all_user?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/gaah/calendar/who.rb', line 27

def catch_all_user?
  self.email.to_s =~ /^\.@/
end

#is_calendar?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/gaah/calendar/who.rb', line 23

def is_calendar?
  email.end_with?('@group.calendar.google.com')
end

#is_resource?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/gaah/calendar/who.rb', line 19

def is_resource?
  resource || email.end_with?('@resource.calendar.google.com')
end

#to_json(*args) ⇒ Object



31
32
33
34
35
36
# File 'lib/gaah/calendar/who.rb', line 31

def to_json(*args)
  {
    name:  name,
    email: email,
  }.to_json
end

#typeObject



11
12
13
14
15
16
17
# File 'lib/gaah/calendar/who.rb', line 11

def type
  case
  when is_resource? then "resource"
  when is_calendar? then "calendar"
  else "user"
  end
end