Class: Vcard::V3_0::PropertyValue::Text

Inherits:
Vobject::PropertyValue show all
Defined in:
lib/vobject/vcard/v3_0/propertyvalue.rb

Instance Attribute Summary

Attributes inherited from Vobject::PropertyValue

#errors, #norm, #type, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Vobject::PropertyValue

#<=>, #name, #to_norm

Constructor Details

#initialize(val) ⇒ Text

Returns a new instance of Text.



25
26
27
28
# File 'lib/vobject/vcard/v3_0/propertyvalue.rb', line 25

def initialize(val)
  self.value = val
  self.type = "text"
end

Class Method Details

.escape(x) ⇒ Object



8
9
10
11
# File 'lib/vobject/vcard/v3_0/propertyvalue.rb', line 8

def escape(x)
  # temporarily escape \\ as \u007f, which is banned from text
  x.tr("\\", "\u007f").gsub(/\n/, "\\n").gsub(/,/, "\\,").gsub(/;/, "\\;").gsub(/\u007f/, "\\\\")
end

.listencode(x) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/vobject/vcard/v3_0/propertyvalue.rb', line 13

def listencode(x)
  ret = if x.is_a?(Array)
          x.map { |m| Text.escape m }.join(",")
        elsif x.nil? || x.empty?
          ""
        else
          Text.escape x
        end
  ret
end

Instance Method Details

#to_hashObject



34
35
36
# File 'lib/vobject/vcard/v3_0/propertyvalue.rb', line 34

def to_hash
  value
end

#to_sObject



30
31
32
# File 'lib/vobject/vcard/v3_0/propertyvalue.rb', line 30

def to_s
  Text.escape value
end