Class: Icalendar2::Component::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/icalendar2/component/base.rb

Direct Known Subclasses

Alarm, Event, Freebusy, Journal, Timezone, Todo

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



19
20
21
# File 'lib/icalendar2/component/base.rb', line 19

def initialize
  @properties = {}
end

Class Attribute Details

.property_namesObject (readonly)

Returns the value of attribute property_names.



7
8
9
# File 'lib/icalendar2/component/base.rb', line 7

def property_names
  @property_names
end

.required_property_namesObject (readonly)

Returns the value of attribute required_property_names.



8
9
10
# File 'lib/icalendar2/component/base.rb', line 8

def required_property_names
  @required_property_names
end

Class Method Details

.accepts(properties = {}) ⇒ Object



15
16
17
# File 'lib/icalendar2/component/base.rb', line 15

def self.accepts(properties = {})
  add_properties(properties)
end

.requires(properties = {}) ⇒ Object



10
11
12
13
# File 'lib/icalendar2/component/base.rb', line 10

def self.requires(properties = {})
  add_properties(properties)
  @required_property_names = properties.values.flatten
end

Instance Method Details

#new_timestampObject



27
28
29
# File 'lib/icalendar2/component/base.rb', line 27

def new_timestamp
  DateTime.now
end

#new_uidObject



23
24
25
# File 'lib/icalendar2/component/base.rb', line 23

def new_uid
  "#{DateTime.now}_#{rand(999999999)}@#{Socket.gethostname}"
end

#set_property(property_name, value, parameters = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/icalendar2/component/base.rb', line 37

def set_property(property_name, value, parameters = {})
  name = (property_name == "class" ? "klass" : property_name)
  unless self.class.property_names.include? name.to_sym
    raise "#{self.class} component property #{name} not defined"
  end
  self.send(name, value, parameters)
end

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/icalendar2/component/base.rb', line 31

def valid?
  present_property_names = @properties.keys
  @properties.values.flatten.all?(&:valid?) &&
    self.class.required_property_names.all? { |p| present_property_names.include?(p.to_s) }
end