Class: Icalendar2::Component::Base
- Inherits:
-
Object
- Object
- Icalendar2::Component::Base
- Defined in:
- lib/icalendar2/component/base.rb
Class Attribute Summary collapse
-
.property_names ⇒ Object
readonly
Returns the value of attribute property_names.
-
.required_property_names ⇒ Object
readonly
Returns the value of attribute required_property_names.
Class Method Summary collapse
Instance Method Summary collapse
- #add_component(component) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #new_timestamp ⇒ Object
- #new_uid ⇒ Object
- #set_property(property_name, value, parameters = {}) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
19 20 21 22 |
# File 'lib/icalendar2/component/base.rb', line 19 def initialize @components = {} @properties = {} end |
Class Attribute Details
.property_names ⇒ Object (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_names ⇒ Object (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
#add_component(component) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/icalendar2/component/base.rb', line 24 def add_component(component) key = (component.class.to_s.downcase + 's').gsub('icalendar2::', '').to_sym unless @components.has_key? key @components[key] = [] end @components[key] << component end |
#new_timestamp ⇒ Object
38 39 40 |
# File 'lib/icalendar2/component/base.rb', line 38 def DateTime.now end |
#new_uid ⇒ Object
34 35 36 |
# File 'lib/icalendar2/component/base.rb', line 34 def new_uid "#{DateTime.now}_#{rand(999999999)}@#{Socket.gethostname}" end |
#set_property(property_name, value, parameters = {}) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/icalendar2/component/base.rb', line 48 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
42 43 44 45 46 |
# File 'lib/icalendar2/component/base.rb', line 42 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 |