Class: Kali::Property
- Inherits:
-
KeyValuePair
- Object
- KeyValuePair
- Kali::Property
- Defined in:
- lib/kali/property.rb
Overview
Public: Properties are the definition of an attribute describing a component.
Direct Known Subclasses
Attendee, CalendarScale, Categories, Comment, Contact, Description, Duration, EndDateTime, EventStatus, GeographicPosition, Location, Method, Organizer, Priority, ProductIdentifier, Resources, SequenceNumber, StartDateTime, Summary, TimeTransparency, URL, UniqueIdentifier, Version
Defined Under Namespace
Classes: Attendee, CalendarScale, Categories, Comment, Contact, Description, Duration, EndDateTime, EventStatus, GeographicPosition, Location, Method, Organizer, Priority, ProductIdentifier, Resources, SequenceNumber, StartDateTime, Summary, TimeTransparency, URL, UniqueIdentifier, Version
Instance Attribute Summary
Attributes inherited from KeyValuePair
Class Method Summary collapse
-
.default_parameter_types ⇒ Object
Internal: List of parameter types added to the class explicitly.
-
.parameter(type, method = type.method_name) ⇒ Object
Public: Add a new parameter to this Property.
-
.type(type = nil) ⇒ Object
Public: Register the type of this property, and all the parameters associated with that type, or get the current type of the object.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Public: Get a parameter by iCalendar name.
-
#[]=(name, value) ⇒ Object
Public: Set a parameter manually by explicitly passing the iCalendar name (so, for example, “DELEGATED-TO” instead of calling ‘#delegated_to=`).
-
#initialize ⇒ Property
constructor
:nodoc:.
-
#parameters ⇒ Object
Internal: Storage of parameters associated with this instance of the property.
-
#to_ics ⇒ Object
Public: Generate an iCalendar representation of this property.
Methods inherited from KeyValuePair
default, #name, #separator, #to_s, wrap
Methods included from Utils::Named
Constructor Details
#initialize ⇒ Property
:nodoc:
42 43 44 |
# File 'lib/kali/property.rb', line 42 def initialize(*) # :nodoc: super end |
Class Method Details
.default_parameter_types ⇒ Object
Internal: List of parameter types added to the class explicitly. Any parameter added that is not in this store will be assumed to be a simple Type::Text parameter. See ‘Property#[]=`.
38 39 40 |
# File 'lib/kali/property.rb', line 38 def self.default_parameter_types @parameter_types ||= {} end |
.parameter(type, method = type.method_name) ⇒ Object
Public: Add a new parameter to this Property.
type - A subclass of Kali::Parameter.
Returns nothing.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kali/property.rb', line 10 def self.parameter(type, method = type.method_name) default_parameter_types[type.name] = type define_method method do parameters[type.name] ||= type.new end define_method "#{method}=" do |value| parameters[type.name] = type.wrap(value) end end |
.type(type = nil) ⇒ Object
Public: Register the type of this property, and all the parameters associated with that type, or get the current type of the object.
See ‘KeyValuePair.type`.
26 27 28 29 30 31 32 33 |
# File 'lib/kali/property.rb', line 26 def self.type(type = nil) if type type.parameters.each do |param, method| parameter(param, method) end end super end |
Instance Method Details
#[](name) ⇒ Object
Public: Get a parameter by iCalendar name.
name - The name of the parameter.
Returns the passed in value.
59 60 61 |
# File 'lib/kali/property.rb', line 59 def [](name) parameters[name] end |
#[]=(name, value) ⇒ Object
Public: Set a parameter manually by explicitly passing the iCalendar name (so, for example, “DELEGATED-TO” instead of calling ‘#delegated_to=`).
name - A String with the name of the parameter. If there’s a typed
parameter for this name already, this will be equivalent to
setting that parameter via the setter. Otherwise it will assume
this is a Text parameter and set it. Useful for setting
experimental ("X-*") params, such as "X-GUEST-COUNT".
value - The value of the param.
Returns the passed in value.
74 75 76 77 78 79 80 81 82 |
# File 'lib/kali/property.rb', line 74 def []=(name, value) param = if type = self.class.default_parameter_types.fetch(name, false) type.wrap(value) else Parameter::Default.new(name, value) end parameters[name] = param end |
#parameters ⇒ Object
Internal: Storage of parameters associated with this instance of the property.
Returns a Hash.
50 51 52 |
# File 'lib/kali/property.rb', line 50 def parameters @parameters ||= {} end |
#to_ics ⇒ Object
Public: Generate an iCalendar representation of this property.
Returns a String.
87 88 89 90 91 |
# File 'lib/kali/property.rb', line 87 def to_ics params = parameters.map { |_, value| value.to_ics }.join("") encoded_value = self.class.type.encode(value) Utils::Text.fold_line "#{self.class.name}#{params}:#{encoded_value}" end |