omniship 0.1.0 → 0.3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -1,5 +1,4 @@
1
- [![Code
2
- Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Digi-Cazter/omniship)
1
+ [![Gem Version](https://badge.fury.io/rb/omniship.png)](http://badge.fury.io/rb/omniship) [![Code Climate](https://codeclimate.com/github/Digi-Cazter/omniship.png)](https://codeclimate.com/github/Digi-Cazter/omniship)
3
2
 
4
3
  # Omniship
5
4
 
@@ -1,14 +1,14 @@
1
1
  module Omniship #:nodoc:
2
- class Address
2
+ class Address
3
3
  ADDRESS_TYPES = %w{residential commercial po_box}
4
-
4
+
5
5
  attr_reader :options,
6
6
  :country,
7
7
  :postal_code,
8
8
  :province,
9
9
  :city,
10
10
  :name,
11
- :attention_name,
11
+ :attention_name,
12
12
  :address1,
13
13
  :address2,
14
14
  :address3,
@@ -16,18 +16,18 @@ module Omniship #:nodoc:
16
16
  :fax,
17
17
  :address_type,
18
18
  :company_name
19
-
19
+
20
20
  alias_method :zip, :postal_code
21
21
  alias_method :postal, :postal_code
22
22
  alias_method :state, :province
23
23
  alias_method :territory, :province
24
24
  alias_method :region, :province
25
25
  alias_method :company, :company_name
26
-
26
+
27
27
  def initialize(options = {})
28
28
  @country = (options[:country].nil? or options[:country].is_a?(ActiveMerchant::Country)) ?
29
- options[:country] :
30
- ActiveMerchant::Country.find(options[:country])
29
+ options[:country] :
30
+ ActiveMerchant::Country.find(options[:country])
31
31
  @postal_code = options[:postal_code] || options[:postal] || options[:zip]
32
32
  @province = options[:province] || options[:state] || options[:territory] || options[:region]
33
33
  @city = options[:city]
@@ -38,25 +38,27 @@ module Omniship #:nodoc:
38
38
  @phone = options[:phone]
39
39
  @fax = options[:fax]
40
40
  @company_name = options[:company_name] || options[:company]
41
+ @attention_name = options[:attention_name]
41
42
 
42
43
  self.address_type = options[:address_type]
43
44
  end
44
-
45
+
45
46
  def self.from(object, options={})
46
47
  return object if object.is_a? Omniship::Address
47
48
  attr_mappings = {
48
- :name => [:name],
49
- :country => [:country_code, :country],
50
- :postal_code => [:postal_code, :zip, :postal],
51
- :province => [:province_code, :state_code, :territory_code, :region_code, :province, :state, :territory, :region],
52
- :city => [:city, :town],
53
- :address1 => [:address1, :address, :street],
54
- :address2 => [:address2],
55
- :address3 => [:address3],
56
- :phone => [:phone, :phone_number],
57
- :fax => [:fax, :fax_number],
58
- :address_type => [:address_type],
59
- :company_name => [:company, :company_name]
49
+ :name => [:name],
50
+ :attention_name => [:attention_name],
51
+ :country => [:country_code, :country],
52
+ :postal_code => [:postal_code, :zip, :postal],
53
+ :province => [:province_code, :state_code, :territory_code, :region_code, :province, :state, :territory, :region],
54
+ :city => [:city, :town],
55
+ :address1 => [:address1, :address, :street],
56
+ :address2 => [:address2],
57
+ :address3 => [:address3],
58
+ :phone => [:phone, :phone_number],
59
+ :fax => [:fax, :fax_number],
60
+ :address_type => [:address_type],
61
+ :company_name => [:company, :company_name]
60
62
  }
61
63
  attributes = {}
62
64
  hash_access = begin
@@ -76,11 +78,11 @@ module Omniship #:nodoc:
76
78
  attributes.delete(:address_type) unless ADDRESS_TYPES.include?(attributes[:address_type].to_s)
77
79
  self.new(attributes.update(options))
78
80
  end
79
-
81
+
80
82
  def country_code(format = :alpha2)
81
83
  @country.nil? ? nil : @country.code(format).value
82
84
  end
83
-
85
+
84
86
  def residential?; @address_type == 'residential' end
85
87
  def commercial?; @address_type == 'commercial' end
86
88
  def po_box?; @address_type == 'po_box' end
@@ -93,18 +95,19 @@ module Omniship #:nodoc:
93
95
 
94
96
  def to_hash
95
97
  {
96
- :country => country_code,
97
- :postal_code => postal_code,
98
- :province => province,
99
- :city => city,
100
- :name => name,
101
- :address1 => address1,
102
- :address2 => address2,
103
- :address3 => address3,
104
- :phone => phone,
105
- :fax => fax,
106
- :address_type => address_type,
107
- :company_name => company_name
98
+ :country => country_code,
99
+ :postal_code => postal_code,
100
+ :province => province,
101
+ :city => city,
102
+ :name => name,
103
+ :address1 => address1,
104
+ :address2 => address2,
105
+ :address3 => address3,
106
+ :phone => phone,
107
+ :fax => fax,
108
+ :address_type => address_type,
109
+ :company_name => company_name,
110
+ :attention_name => attention_name
108
111
  }
109
112
  end
110
113
 
@@ -116,15 +119,15 @@ module Omniship #:nodoc:
116
119
  def to_s
117
120
  prettyprint.gsub(/\n/, ' ')
118
121
  end
119
-
122
+
120
123
  def prettyprint
121
124
  chunks = []
122
- chunks << [@name, @address1,@address2,@address3].reject {|e| e.blank?}.join("\n")
125
+ chunks << [@name,@attention_name,@address1,@address2,@address3].reject {|e| e.blank?}.join("\n")
123
126
  chunks << [@city,@province,@postal_code].reject {|e| e.blank?}.join(', ')
124
127
  chunks << @country
125
128
  chunks.reject {|e| e.blank?}.join("\n")
126
129
  end
127
-
130
+
128
131
  def inspect
129
132
  string = prettyprint
130
133
  string << "\nPhone: #{@phone}" unless @phone.blank?