Class: Icalendar2::Property::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/icalendar2/property/base.rb

Constant Summary collapse

MAX_LINE_LENGTH =
75

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, parameters = {}) ⇒ Base

Returns a new instance of Base.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/icalendar2/property/base.rb', line 26

def initialize(value, parameters = {})
  @value = if list?
    value_list = value.respond_to?(:gsub) ? split_list(value) : value
    value_list.map { |v| value_object(v) }
  else
    value_object(value)
  end
  if @value.nil?
    raise "Invalid value for #{self.class}: '#{value}'. Must be one of these types: #{self.class.value_types}"
  end
  @parameters = parameters || {}
  validate
end

Class Attribute Details

.value_factoriesObject (readonly)

Returns the value of attribute value_factories.



9
10
11
# File 'lib/icalendar2/property/base.rb', line 9

def value_factories
  @value_factories
end

.value_typesObject (readonly)

Returns the value of attribute value_types.



8
9
10
# File 'lib/icalendar2/property/base.rb', line 8

def value_types
  @value_types
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



6
7
8
# File 'lib/icalendar2/property/base.rb', line 6

def parameters
  @parameters
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/icalendar2/property/base.rb', line 6

def value
  @value
end

Class Method Details

.name(str) ⇒ Object



22
23
24
# File 'lib/icalendar2/property/base.rb', line 22

def self.name(str)
  define_method(:name) { str }
end

.value(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/icalendar2/property/base.rb', line 11

def self.value(options = {})
  if !options[:types].respond_to?(:map)
    raise ":types option must be enumberable, was #{options[:types]}"
  end
  @value_types = options[:types]
  @value_factories = options[:types].map { |t| Value.get_factory(t) }
  define_method(:list?) do
    options[:list]
  end
end

Instance Method Details

#nameObject



40
41
42
# File 'lib/icalendar2/property/base.rb', line 40

def name
  raise "Must define name attribute in Property sublcass #{self.class}."
end

#to_icalObject



48
49
50
51
52
53
# File 'lib/icalendar2/property/base.rb', line 48

def to_ical
  parameters_str = @parameters.map { |k, v| "#{k}=#{v}" }.join(";")
  parameters_str = ";#{parameters_str}" if parameters_str != ""
  str = fold("#{name}#{parameters_str}:#{value}")
  str << Tokens::CRLF
end

#valid?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/icalendar2/property/base.rb', line 44

def valid?
  @valid
end