Class: Vcard::V4_0::PropertyValue::Text

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

Direct Known Subclasses

Clientpidmap, Ianatoken, Kindvalue, Lang, Uri

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.



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

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

Class Method Details

.escape(x) ⇒ Object



8
9
10
11
# File 'lib/vobject/vcard/v4_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(/\u007f/, "\\\\")
end

.escape_component(x) ⇒ Object



13
14
15
16
# File 'lib/vobject/vcard/v4_0/propertyvalue.rb', line 13

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

.listencode(x) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/vobject/vcard/v4_0/propertyvalue.rb', line 18

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

Instance Method Details

#to_hashObject



39
40
41
# File 'lib/vobject/vcard/v4_0/propertyvalue.rb', line 39

def to_hash
  value
end

#to_sObject



35
36
37
# File 'lib/vobject/vcard/v4_0/propertyvalue.rb', line 35

def to_s
  Text.escape value
end