module Icalendar::HasProperties

Public Class Methods

included(base) click to toggle source
# File lib/icalendar/has_properties.rb, line 7
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 14
def initialize(*args)
  @custom_properties = Hash.new
  super
end

Public Instance Methods

append_custom_property(property_name, value) click to toggle source
# File lib/icalendar/has_properties.rb, line 47
def append_custom_property(property_name, value)
  property_name = property_name.downcase
  if self.class.single_properties.include? property_name
    send "#{property_name}=", value
  elsif self.class.multiple_properties.include? property_name
    send "append_#{property_name}", value
  elsif 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 43
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 60
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 34
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 73
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 19
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, new_property) click to toggle source
# File lib/icalendar/has_properties.rb, line 174
def map_property_value(value, klass, multi_valued, new_property)
  params = {}
  if new_property
    params.merge!('VALUE': klass.value_type)
  end
  if value.nil? || value.is_a?(Icalendar::Value)
    value
  elsif value.is_a? ::Array
    Icalendar::Values::Helpers::Array.new value, klass, params, {delimiter: (multi_valued ? ',' : ';')}
  else
    klass.new value, params
  end
end