module Icalendar::HasProperties

Public Class Methods

included(base) click to toggle source
# File lib/icalendar/has_properties.rb, line 5
def self.included(base)
  base.extend ClassMethods
  base.class_eval do
    attr_reader :custom_properties
  end
end
new(*args) click to toggle source
Calls superclass method
# File lib/icalendar/has_properties.rb, line 12
def initialize(*args)
  @custom_properties = Hash.new { |h, k| h[k] = [] }
  super
end

Public Instance Methods

append_custom_property(property_name, value) click to toggle source
# File lib/icalendar/has_properties.rb, line 45
def append_custom_property(property_name, value)
  property_name = property_name.downcase
  if value.is_a? Icalendar::Value
    custom_properties[property_name] << value
  else
    custom_properties[property_name] << Icalendar::Values::Text.new(value)
  end
end
custom_property(property_name) click to toggle source
# File lib/icalendar/has_properties.rb, line 41
def custom_property(property_name)
  custom_properties[property_name.downcase]
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/icalendar/has_properties.rb, line 54
def method_missing(method, *args, &block)
  method_name = method.to_s
  if method_name.start_with? 'x_'
    if method_name.end_with? '='
      append_custom_property method_name.chomp('='), args.first
    else
      custom_property method_name
    end
  else
    super
  end
end
property(property_name) click to toggle source
# File lib/icalendar/has_properties.rb, line 32
def property(property_name)
  property_name = property_name.downcase
  if self.class.properties.include? property_name
    send property_name
  else
    custom_property property_name
  end
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/icalendar/has_properties.rb, line 67
def respond_to_missing?(method, include_private = false)
  method.to_s.start_with?('x_') || super
end
valid?(strict = false) click to toggle source
# File lib/icalendar/has_properties.rb, line 17
def valid?(strict = false)
  self.class.required_properties.each_pair do |prop, validator|
    validator.call(self, send(prop)) or return false
  end
  self.class.mutex_properties.each do |mutexprops|
    mutexprops.map { |p| send p }.compact.size > 1 and return false
  end
  if strict
    self.class.suggested_single_properties.each do |single_prop|
      send(single_prop).size > 1 and return false
    end
  end
  true
end

Private Instance Methods

map_property_value(value, klass, multi_valued) click to toggle source
# File lib/icalendar/has_properties.rb, line 168
def map_property_value(value, klass, multi_valued)
  if value.nil? || value.is_a?(Icalendar::Value)
    value
  elsif value.is_a? ::Array
    Icalendar::Values::Array.new value, klass, {}, {delimiter: (multi_valued ? ',' : ';')}
  else
    klass.new value
  end
end