Class: XeroGateway::Phone
- Inherits:
-
Object
- Object
- XeroGateway::Phone
- Defined in:
- lib/xero_gateway/phone.rb
Constant Summary collapse
- PHONE_TYPE =
{ 'DEFAULT' => 'Default', 'DDI' => 'Direct Dial-In', 'MOBILE' => 'Mobile', 'FAX' => 'Fax' }
Instance Attribute Summary collapse
-
#area_code ⇒ Object
Returns the value of attribute area_code.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#errors ⇒ Object
readonly
Any errors that occurred when the #valid? method called.
-
#number ⇒ Object
Returns the value of attribute number.
-
#phone_type ⇒ Object
Returns the value of attribute phone_type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(params = {}) ⇒ Phone
constructor
A new instance of Phone.
- #to_xml(b = Builder::XmlMarkup.new) ⇒ Object
-
#valid? ⇒ Boolean
Validate the Phone record according to what will be valid by the gateway.
Constructor Details
#initialize(params = {}) ⇒ Phone
Returns a new instance of Phone.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/xero_gateway/phone.rb', line 16 def initialize(params = {}) @errors ||= [] params = { :phone_type => "DEFAULT" }.merge(params) params.each do |k,v| self.send("#{k}=", v) end end |
Instance Attribute Details
#area_code ⇒ Object
Returns the value of attribute area_code.
14 15 16 |
# File 'lib/xero_gateway/phone.rb', line 14 def area_code @area_code end |
#country_code ⇒ Object
Returns the value of attribute country_code.
14 15 16 |
# File 'lib/xero_gateway/phone.rb', line 14 def country_code @country_code end |
#errors ⇒ Object (readonly)
Any errors that occurred when the #valid? method called.
12 13 14 |
# File 'lib/xero_gateway/phone.rb', line 12 def errors @errors end |
#number ⇒ Object
Returns the value of attribute number.
14 15 16 |
# File 'lib/xero_gateway/phone.rb', line 14 def number @number end |
#phone_type ⇒ Object
Returns the value of attribute phone_type.
14 15 16 |
# File 'lib/xero_gateway/phone.rb', line 14 def phone_type @phone_type end |
Class Method Details
.from_xml(phone_element) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/xero_gateway/phone.rb', line 57 def self.from_xml(phone_element) phone = Phone.new phone_element.children.each do |element| case(element.name) when "PhoneType" then phone.phone_type = element.text when "PhoneNumber" then phone.number = element.text when "PhoneAreaCode" then phone.area_code = element.text when "PhoneCountryCode" then phone.country_code = element.text end end phone end |
Instance Method Details
#==(other) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/xero_gateway/phone.rb', line 70 def ==(other) [:phone_type, :number, :area_code, :country_code].each do |field| return false if send(field) != other.send(field) end return true end |
#to_xml(b = Builder::XmlMarkup.new) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/xero_gateway/phone.rb', line 48 def to_xml(b = Builder::XmlMarkup.new) b.Phone { b.PhoneType phone_type b.PhoneNumber number b.PhoneAreaCode area_code if area_code b.PhoneCountryCode country_code if country_code } end |
#valid? ⇒ Boolean
Validate the Phone record according to what will be valid by the gateway.
Usage:
phone.valid? # Returns true/false
Additionally sets phone.errors array to an array of field/error.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/xero_gateway/phone.rb', line 34 def valid? @errors = [] unless number @errors << ['number', "can't be blank"] end if phone_type && !PHONE_TYPE[phone_type] @errors << ['phone_type', "must be one of #{PHONE_TYPE.keys.join('/')}"] end @errors.size == 0 end |