Class: Icalendar2::Component::Base
- Inherits:
-
Object
- Object
- Icalendar2::Component::Base
- Defined in:
- lib/icalendar2/component/base.rb
Direct Known Subclasses
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
-
#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 |
# File 'lib/icalendar2/component/base.rb', line 19 def initialize @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
#new_timestamp ⇒ Object
27 28 29 |
# File 'lib/icalendar2/component/base.rb', line 27 def DateTime.now end |
#new_uid ⇒ Object
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
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) } end |