Module: Icalendar::HasProperties::ClassMethods

Defined in:
lib/icalendar/has_properties.rb

Instance Method Summary collapse

Instance Method Details

#default_property_typesObject


100
101
102
# File 'lib/icalendar/has_properties.rb', line 100

def default_property_types
  @default_property_types ||= Hash.new { |h,k| Icalendar::Values::Text }
end

#multi_property(prop, klass) ⇒ Object


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/icalendar/has_properties.rb', line 142

def multi_property(prop, klass)
  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
    if mapped.is_a? Icalendar::Values::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)
  end
end

#multiple_propertiesObject


84
85
86
# File 'lib/icalendar/has_properties.rb', line 84

def multiple_properties
  @multiple_properties ||= []
end

#mutex_propertiesObject


96
97
98
# File 'lib/icalendar/has_properties.rb', line 96

def mutex_properties
  @mutex_properties ||= []
end

#mutually_exclusive_properties(*properties) ⇒ Object


120
121
122
# File 'lib/icalendar/has_properties.rb', line 120

def mutually_exclusive_properties(*properties)
  self.mutex_properties << properties
end

#optional_property(prop, klass = Icalendar::Values::Text, suggested_single = false) ⇒ Object


124
125
126
127
# File 'lib/icalendar/has_properties.rb', line 124

def optional_property(prop, klass = Icalendar::Values::Text, suggested_single = false)
  self.suggested_single_properties << prop if suggested_single
  multi_property prop, klass
end

#optional_single_property(prop, klass = Icalendar::Values::Text) ⇒ Object


116
117
118
# File 'lib/icalendar/has_properties.rb', line 116

def optional_single_property(prop, klass = Icalendar::Values::Text)
  single_property prop, klass
end

#propertiesObject


76
77
78
# File 'lib/icalendar/has_properties.rb', line 76

def properties
  single_properties + multiple_properties
end

#required_multi_property(prop, klass = Icalendar::Values::Text, validator = nil) ⇒ Object


110
111
112
113
114
# File 'lib/icalendar/has_properties.rb', line 110

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
end

#required_propertiesObject


88
89
90
# File 'lib/icalendar/has_properties.rb', line 88

def required_properties
  @required_properties ||= {}
end

#required_property(prop, klass = Icalendar::Values::Text, validator = nil) ⇒ Object


104
105
106
107
108
# File 'lib/icalendar/has_properties.rb', line 104

def required_property(prop, klass = Icalendar::Values::Text, validator = nil)
  validator ||= ->(component, value) { !value.nil? }
  self.required_properties[prop] = validator
  single_property prop, klass
end

#single_propertiesObject


80
81
82
# File 'lib/icalendar/has_properties.rb', line 80

def single_properties
  @single_properties ||= []
end

#single_property(prop, klass) ⇒ Object


129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/icalendar/has_properties.rb', line 129

def single_property(prop, klass)
  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)
  end
end

#suggested_single_propertiesObject


92
93
94
# File 'lib/icalendar/has_properties.rb', line 92

def suggested_single_properties
  @suggested_single_properties ||= []
end