Module: Icalendar::HasProperties::ClassMethods
- Defined in:
- lib/icalendar/has_properties.rb
Instance Method Summary collapse
- #default_property_types ⇒ Object
- #multi_property(prop, klass, new_property) ⇒ Object
- #multiple_properties ⇒ Object
- #mutex_properties ⇒ Object
- #mutually_exclusive_properties(*properties) ⇒ Object
- #optional_property(prop, klass = Icalendar::Values::Text, suggested_single = false, new_property = false) ⇒ Object
- #optional_single_property(prop, klass = Icalendar::Values::Text, new_property = false) ⇒ Object
- #properties ⇒ Object
- #required_multi_property(prop, klass = Icalendar::Values::Text, validator = nil) ⇒ Object
- #required_properties ⇒ Object
- #required_property(prop, klass = Icalendar::Values::Text, validator = nil) ⇒ Object
- #single_properties ⇒ Object
- #single_property(prop, klass, new_property) ⇒ Object
- #suggested_single_properties ⇒ Object
Instance Method Details
#default_property_types ⇒ Object
102 103 104 |
# File 'lib/icalendar/has_properties.rb', line 102 def default_property_types @default_property_types ||= Hash.new { |h,k| Icalendar::Values::Text } end |
#multi_property(prop, klass, new_property) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/icalendar/has_properties.rb', line 144 def multi_property(prop, klass, new_property) self.multiple_properties << prop.to_s self.default_property_types[prop.to_s] = klass property_var = "@#{prop}" define_method "#{prop}=" do |value| mapped = map_property_value value, klass, true, new_property if mapped.is_a? Icalendar::Values::Helpers::Array instance_variable_set property_var, mapped.to_a.compact else instance_variable_set property_var, [mapped].compact end end define_method prop do if instance_variable_defined? property_var instance_variable_get property_var else send "#{prop}=", nil end end define_method "append_#{prop}" do |value| send(prop) << map_property_value(value, klass, true, new_property) end end |
#multiple_properties ⇒ Object
86 87 88 |
# File 'lib/icalendar/has_properties.rb', line 86 def multiple_properties @multiple_properties ||= [] end |
#mutex_properties ⇒ Object
98 99 100 |
# File 'lib/icalendar/has_properties.rb', line 98 def mutex_properties @mutex_properties ||= [] end |
#mutually_exclusive_properties(*properties) ⇒ Object
122 123 124 |
# File 'lib/icalendar/has_properties.rb', line 122 def mutually_exclusive_properties(*properties) self.mutex_properties << properties end |
#optional_property(prop, klass = Icalendar::Values::Text, suggested_single = false, new_property = false) ⇒ Object
126 127 128 129 |
# File 'lib/icalendar/has_properties.rb', line 126 def optional_property(prop, klass = Icalendar::Values::Text, suggested_single = false, new_property = false) self.suggested_single_properties << prop if suggested_single multi_property prop, klass, new_property end |
#optional_single_property(prop, klass = Icalendar::Values::Text, new_property = false) ⇒ Object
118 119 120 |
# File 'lib/icalendar/has_properties.rb', line 118 def optional_single_property(prop, klass = Icalendar::Values::Text, new_property = false) single_property prop, klass, new_property end |
#properties ⇒ Object
78 79 80 |
# File 'lib/icalendar/has_properties.rb', line 78 def properties single_properties + multiple_properties end |
#required_multi_property(prop, klass = Icalendar::Values::Text, validator = nil) ⇒ Object
112 113 114 115 116 |
# File 'lib/icalendar/has_properties.rb', line 112 def required_multi_property(prop, klass = Icalendar::Values::Text, validator = nil) validator ||= ->(component, value) { !value.compact.empty? } self.required_properties[prop] = validator multi_property prop, klass, false end |
#required_properties ⇒ Object
90 91 92 |
# File 'lib/icalendar/has_properties.rb', line 90 def required_properties @required_properties ||= {} end |
#required_property(prop, klass = Icalendar::Values::Text, validator = nil) ⇒ Object
106 107 108 109 110 |
# File 'lib/icalendar/has_properties.rb', line 106 def required_property(prop, klass = Icalendar::Values::Text, validator = nil) validator ||= ->(component, value) { !value.nil? } self.required_properties[prop] = validator single_property prop, klass, false end |
#single_properties ⇒ Object
82 83 84 |
# File 'lib/icalendar/has_properties.rb', line 82 def single_properties @single_properties ||= [] end |
#single_property(prop, klass, new_property) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/icalendar/has_properties.rb', line 131 def single_property(prop, klass, new_property) self.single_properties << prop.to_s self.default_property_types[prop.to_s] = klass define_method prop do instance_variable_get "@#{prop}" end define_method "#{prop}=" do |value| instance_variable_set "@#{prop}", map_property_value(value, klass, false, new_property) end end |
#suggested_single_properties ⇒ Object
94 95 96 |
# File 'lib/icalendar/has_properties.rb', line 94 def suggested_single_properties @suggested_single_properties ||= [] end |