Class: VCardio::Property

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

Overview

Content line definition and value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, name, parameters, value) ⇒ Property

Returns a new instance of Property.



11
12
13
14
15
16
# File 'lib/vcardio/property.rb', line 11

def initialize(group, name, parameters, value)
  @group = group ? group.to_s : nil
  @name = name.to_s.upcase
  @parameters = parameters || []
  @value = value
end

Instance Attribute Details

#groupString (readonly)

Returns the current value of group.

Returns:

  • (String)

    the current value of group



10
11
12
# File 'lib/vcardio/property.rb', line 10

def group
  @group
end

#nameString (readonly)

Returns the current value of name.

Returns:

  • (String)

    the current value of name



10
11
12
# File 'lib/vcardio/property.rb', line 10

def name
  @name
end

#parametersArray<VCardio::Parameter> (readonly)

Returns the current value of parameters.

Returns:



10
11
12
# File 'lib/vcardio/property.rb', line 10

def parameters
  @parameters
end

#valueString, Array (readonly)

Returns the current value of value.

Returns:

  • (String, Array)

    the current value of value



10
11
12
# File 'lib/vcardio/property.rb', line 10

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/vcardio/property.rb', line 38

def ==(other)
  other.is_a?(VCardio::Property) &&
    other.group == group &&
    other.name == name &&
    other.parameters == parameters &&
    other.value == value
end

#to_abnf(spec) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vcardio/property.rb', line 20

def to_abnf(spec)
  abnf = @group || ''
  parameters = []
  abnf += '.' if @group
  abnf += @name

  @parameters.each do |parameter|
    parameters << parameter.to_abnf(spec)
  end

  abnf += parameters.size > 0 ? ';' : ''
  abnf += parameters.join(';')
  abnf += ':'
  abnf += @value.is_a?(Array) ? @value.join(';') : @value.to_s

  abnf
end