Module: Vpim::Icalendar::Set::Util

Included in:
Vevent::Maker
Defined in:
lib/vpim/property/base.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#add_address(name, value) ⇒ Object



77
78
79
80
# File 'lib/vpim/property/base.rb', line 77

def add_address(name, value)
  f = value.encode(name)
  @comp.properties.push(f)
end

#field_create(name, value, default_value_type = nil, value_type = nil, params = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/vpim/property/base.rb', line 31

def field_create(name, value, default_value_type = nil, value_type = nil, params = {})
  if value_type && value_type != default_value_type
    params['VALUE'] = value_type
  end
  Vpim::DirectoryInfo::Field.create(name, value, params)
end

#rm_all(name) ⇒ Object

TODO - rename module to Private?



15
16
17
18
# File 'lib/vpim/property/base.rb', line 15

def rm_all(name)
  rm = @comp.properties.select { |f| f.name? name }
  rm.each { |f| @comp.properties.delete(f) }
end

#set_address(name, value) ⇒ Object



82
83
84
85
# File 'lib/vpim/property/base.rb', line 82

def set_address(name, value)
  rm_all(name)
  add_address(name, value)
end

#set_date_or_datetime(name, default, value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vpim/property/base.rb', line 38

def set_date_or_datetime(name, default, value)
  f = nil
  case value
  when Date
    f = field_create(name, Vpim.encode_date(value), default, 'DATE')
  when Time
    f = field_create(name, Vpim.encode_date_time(value), default, 'DATE-TIME')
  else
    raise Vpim::Unencodeable, "Invalid #{name} value #{value.inspect}"
  end
  rm_all(name)
  @comp.properties.push(f)
end

#set_datetime(name, value) ⇒ Object



52
53
54
55
56
# File 'lib/vpim/property/base.rb', line 52

def set_datetime(name, value)
  f = field_create(name, Vpim.encode_date_time(value))
  rm_all(name)
  @comp.properties.push(f)
end

#set_integer(name, value) ⇒ Object



70
71
72
73
74
75
# File 'lib/vpim/property/base.rb', line 70

def set_integer(name, value)
  value = value.to_int.to_s
  f = field_create(name, value)
  rm_all(name)
  @comp.properties.push(f)
end

#set_text(name, value) ⇒ Object



58
59
60
61
62
# File 'lib/vpim/property/base.rb', line 58

def set_text(name, value)
  f = field_create(name, Vpim.encode_text(value))
  rm_all(name)
  @comp.properties.push(f)
end

#set_text_list(name, value) ⇒ Object



64
65
66
67
68
# File 'lib/vpim/property/base.rb', line 64

def set_text_list(name, value)
  f = field_create(name, Vpim.encode_text_list(value))
  rm_all(name)
  @comp.properties.push(f)
end

#set_token(name, allowed, default, value) ⇒ Object

:nodoc:



20
21
22
23
24
25
26
27
28
29
# File 'lib/vpim/property/base.rb', line 20

def set_token(name, allowed, default, value) #:nodoc:
  value = value.to_str
  unless allowed.include?(value)
    raise Vpim::Unencodeable, "Invalid #{name} value '#{value}'"
  end
  rm_all(name)
  unless value == default
    @comp.properties.push Vpim::DirectoryInfo::Field.create(name, value)
  end
end