Class: Virginity::Tel
- Inherits:
-
BaseField
- Object
- ContentLine
- BaseField
- Virginity::Tel
- Includes:
- FieldValues::Text, Params::Type
- Defined in:
- lib/virginity/vcard/fields.rb,
lib/virginity/api_extensions.rb,
lib/virginity/api_extensions/fields_to_xml.rb
Overview
telephone number
provides the easy getter/setter #number and generators for random numbers
Constant Summary collapse
- COMPARISON_REGEX =
anything that is NOT a plus, a star, a hash, a slash, a comma, or 0-9/a-z/A-Z is insignificant
/[^\+\*\#\/\,\w]/u
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
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #significant_chars ⇒ Object (also: #normalized_number)
- #to_xml(options = {}) ⇒ Object
Methods included from Params::Type
#add_type, #location, #location=, #locations, #locations=, #preferred=, #preferred?, #remove_type, #type=, #types, #types=
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
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
Class Method Details
.at_random ⇒ Object
181 182 183 |
# File 'lib/virginity/vcard/fields.rb', line 181 def self.at_random new("TEL", random_number) end |
.random_number(length = 10) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/virginity/vcard/fields.rb', line 174 def self.random_number(length = 10) # (1..length).map { rand(10).to_s }.join # only 555-0100 through 555-0199 are now specifically reserved for fictional use random_part = 100 + (rand(99) + 1) "555-0#{random_part}" end |
Instance Method Details
#as_json(options = {}) ⇒ Object
70 71 72 |
# File 'lib/virginity/api_extensions.rb', line 70 def as_json( = {}) field_as_json({ :number => number }, ) end |
#significant_chars ⇒ Object Also known as: normalized_number
185 186 187 188 189 |
# File 'lib/virginity/vcard/fields.rb', line 185 def significant_chars # it's a phone number (but people could store alphanumeric stuff here) so I opt to remove all dashes and spaces # I leave the plus since we don't know with what prefix to replace it with, see: http://en.wikipedia.org/wiki/List_of_international_call_prefixes number.gsub(COMPARISON_REGEX, "") end |
#to_xml(options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/virginity/api_extensions/fields_to_xml.rb', line 66 def to_xml( = {}) xml = [:builder] || Builder::XmlMarkup.new() xml.telephone(:index => api_id ) do xml.id api_id, :type => "string" # params_to_xml!(params, xml) xml.number number extra_fields_to_xml([:include], xml) end xml.target! end |