Module: Vpim::Icalendar::Property::Base

Included in:
Vevent, Vjournal, Vtodo
Defined in:
lib/vpim/property/base.rb

Overview

FIXME - rename Base to Util

Instance Method Summary collapse

Instance Method Details

#propduration(endfield) ⇒ Object

Duration has “almost” the same definition for Event and Todo



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vpim/property/base.rb', line 162

def propduration(endfield)
  dur = @properties.field 'DURATION'
  dte = @properties.field endfield

  if !dur
    return nil unless dte

    b = dtstart
    e = send(endfield.downcase.to_sym)

    return (e - b).to_i
  end

  Icalendar.decode_duration(dur.value_raw)
end

#propend(endfield) ⇒ Object



178
179
180
181
182
183
184
185
186
187
# File 'lib/vpim/property/base.rb', line 178

def propend(endfield)
  dte = @properties.field endfield.to_s.upcase
  if dte
    dte.to_time.first
  elsif duration
    dtstart + duration
  else
    nil
  end
end

#propinteger(name) ⇒ Object

:nodoc:



110
111
112
113
114
115
116
# File 'lib/vpim/property/base.rb', line 110

def propinteger(name) #:nodoc:
  prop = @properties.detect { |f| f.name? name }
  if prop
    prop = Vpim.decode_integer(prop.value)
  end
  prop
end

#proptext(name) ⇒ Object

Value as TEXT of first property with name name



143
144
145
146
147
148
149
# File 'lib/vpim/property/base.rb', line 143

def proptext(name) #:nodoc:
  prop = @properties.detect { |f| f.name? name }
  if prop
    prop = prop.to_text
  end
  prop
end

#proptextarray(name) ⇒ Object

Array of values as TEXT of all properties with name name



152
153
154
# File 'lib/vpim/property/base.rb', line 152

def proptextarray(name) #:nodoc:
  @properties.select{ |f| f.name? name }.map{ |p| p.to_text }
end

#proptextlistarray(name) ⇒ Object

Array of values as TEXT list of all properties with name name



157
158
159
# File 'lib/vpim/property/base.rb', line 157

def proptextlistarray(name) #:nodoc:
  @properties.select{ |f| f.name? name }.map{ |p| Vpim.decode_text_list(p.value_raw) }.flatten
end

#proptime(name) ⇒ Object

Value as DATE-TIME or DATE of object of first property with name name



134
135
136
137
138
139
140
# File 'lib/vpim/property/base.rb', line 134

def proptime(name) #:nodoc:
  prop = @properties.detect { |f| f.name? name }
  if prop
    prop = prop.to_time.first
  end
  prop
end

#proptoken(name, allowed, default_token = nil) ⇒ Object

:nodoc:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/vpim/property/base.rb', line 118

def proptoken(name, allowed, default_token = nil) #:nodoc:
  prop = propvalue(name)

  if prop
    prop = prop.to_str.upcase
    unless allowed.include?(prop)
      raise Vpim::InvalidEncodingError, "Invalid #{name} value '#{prop}'"
    end
  else
    prop = default_token
  end

  prop
end

#propvalue(name) ⇒ Object

Value of first property with name name



96
97
98
99
100
101
102
# File 'lib/vpim/property/base.rb', line 96

def propvalue(name) #:nodoc:
  prop = @properties.detect { |f| f.name? name }
  if prop
    prop = prop.value
  end
  prop
end

#propvaluearray(name) ⇒ Object

Array of values of all properties with name name



105
106
107
# File 'lib/vpim/property/base.rb', line 105

def propvaluearray(name) #:nodoc:
  @properties.select{ |f| f.name? name }.map{ |p| p.value }
end