Class: Virginity::Impp

Inherits:
BaseField show all
Includes:
FieldValues::Text, FieldValues::Uri, Params::Type
Defined in:
lib/virginity/vcard/fields.rb,
lib/virginity/api_extensions/fields_to_xml.rb

Overview

Instant messaging fields are defined in rfc 2427. They have a scheme and an address. If an IMPP is not ‘clean’ one can still get/set the value by using the methods from FieldValues::Text and FieldValues::Uri

Constant Summary

Constants inherited from BaseField

BaseField::BEGIN_REGEX, BaseField::END_REGEX, BaseField::PREF, BaseField::TYPE

Constants included from FieldCleaning

FieldCleaning::BOM_BINARY, FieldCleaning::BOM_UTF8, FieldCleaning::CASE_SENSITIVE_TYPES, FieldCleaning::CHARSET, FieldCleaning::ENCODING, FieldCleaning::LIST_NAMES, FieldCleaning::QUOTED_PRINTABLE, FieldCleaning::TYPE, FieldCleaning::X_SYNTHESIS_REF

Constants inherited from ContentLine

ContentLine::COLON_CHAR, ContentLine::GROUP, ContentLine::GROUP_DELIMITER, ContentLine::NAME

Instance Attribute Summary

Attributes inherited from ContentLine

#group, #name, #params, #value

Instance Method Summary collapse

Methods included from Params::Type

#add_type, #location, #location=, #locations, #locations=, #preferred=, #preferred?, #remove_type, #type=, #types, #types=

Methods included from FieldValues::Uri

#uri, #uri=

Methods included from FieldValues::Text

#reencode!, #text, #text=, #value_to_xml

Methods inherited from BaseField

#<=>, #==, [], #extra_fields_to_xml, #field_as_json, field_register, #group_and_params_as_json, merger, named, #params_to_xml, #params_to_xml!, parse, #pref?, #raw_value=, register_field, register_for, registered?, types, unregister, #value, #value=, #value_to_xml

Methods included from FieldCleaning

#clean!, #clean_base64!, #clean_binary_data!, #clean_charsets!, #clean_quoted_printable_encoding!, #clean_types!, #guess_latin!, #remove_bom!, #remove_encoding_8bit!, #remove_x_synthesis_ref_params!, #uniq_params!

Methods included from Vcard21::Writer

#encode21, #vcard21line

Methods inherited from ContentLine

#<=>, #==, #api_id, #encode, #eql?, #has_name?, #hash, #initialize, line_parts, #merge_with!, merger, #param_values, #params_to_s, parse, #pretty_print, #to_field

Methods included from Encodings

#binary?, #to_ascii, #to_binary, #to_default, #to_default!, #verify_utf8ness

Constructor Details

This class inherits a constructor from Virginity::ContentLine

Instance Method Details

#addressObject



67
68
69
70
71
# File 'lib/virginity/vcard/fields.rb', line 67

def address
  # everything after the first colon if that colon is present, otherwise the whole text
  text.match(/^.*?:(.*)$|^(.*)$/)
  $1 || $2
end

#address=(s) ⇒ Object



77
78
79
# File 'lib/virginity/vcard/fields.rb', line 77

def address=(s)
  self.text = "#{self.scheme}:#{s}"
end

#raw_valueObject



81
82
83
# File 'lib/virginity/vcard/fields.rb', line 81

def raw_value
  scheme.empty? && address.empty? ? "" : @value
end

#schemeObject

def initialize(content_line=ContentLine.new(“IMPP:”))

  super
  @cline.name = "IMPP"
end


61
62
63
64
65
# File 'lib/virginity/vcard/fields.rb', line 61

def scheme
  # every piece of text before the first colon, if there is a colon present
  text.match(/^(.*?):/) # Note the use of "*?" for non greedy matching of the colon!
  $1 || ""
end

#scheme=(s) ⇒ Object



73
74
75
# File 'lib/virginity/vcard/fields.rb', line 73

def scheme=(s)
  self.text = "#{s}:#{address}"
end

#to_xml(options = {}) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/virginity/api_extensions/fields_to_xml.rb', line 124

def to_xml(options = {})
  xml = options[:builder] || Builder::XmlMarkup.new(options)
  xml.impp(:index => api_id ) do
    xml.id api_id, :type => "string"
    xml.scheme scheme
    xml.address address
    xml.value text
    extra_fields_to_xml(options[:include], xml)
  end
  xml.target!
end