public
Fork of Shopify/active_shipping
Description: Shipping API extension for Active Merchant.
Clone URL: git://github.com/bobby/active_shipping.git
Added equivalence methods to ActiveMerchant::Shipping::Location

Also added equivalence methods to ActiveMerchant::Country and 
ActiveMerchant::CountryCode in order to have deep equivalence on 
ActiveMerchant::Shipping::Location.
bobby (author)
Fri Jun 06 13:07:25 -0700 2008
commit  95d16af06b2d7458fc6e84cd86e945838dcb69c4
tree    2aa72fb401df7f01be9b8c855e507f97137ecf2f
parent  7f0640129e6f71d2da4e150428441ad414e07a95
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
4
 
5
6
7
8
9
10
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
16
17
18
19
20
21
 
22
23
24
25
 
 
26
27
28
...
32
33
34
35
 
36
37
 
38
39
40
...
63
64
65
66
 
67
68
69
70
 
71
72
73
74
 
75
76
77
...
79
80
81
82
 
83
84
85
86
87
88
89
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
92
93
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
31
32
 
 
 
 
 
 
 
 
 
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
48
49
50
 
 
51
52
53
54
55
...
59
60
61
 
62
63
 
64
65
66
67
...
90
91
92
 
93
94
95
96
 
97
98
99
100
 
101
102
103
104
...
106
107
108
 
109
110
111
112
113
114
115
 
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
0
@@ -1,28 +1,55 @@
0
 module ActiveMerchant #:nodoc:
0
+ class Country
0
+ def ==(obj)
0
+ obj.equal?(self) || (obj.instance_of?(self.class) &&
0
+ @name == obj.name &&
0
+ code(:alpha2) == obj.code(:alpha2) &&
0
+ code(:alpha3) == obj.code(:alpha3) &&
0
+ code(:numeric) == obj.code(:numeric))
0
+ end
0
+
0
+ def eql?(obj)
0
+ self == obj
0
+ end
0
+ end
0
+
0
+ class CountryCode
0
+ def ==(obj)
0
+ obj.equal?(self) || (obj.instance_of?(self.class) &&
0
+ @value == obj.value &&
0
+ @format == obj.format
0
+ )
0
+ end
0
+
0
+ def eql?(obj)
0
+ self == obj
0
+ end
0
+ end
0
+
0
   module Shipping #:nodoc:
0
     class Location
0
-
0
+
0
       attr_reader :options,
0
- :country,
0
- :postal_code,
0
- :province,
0
- :city,
0
- :address1,
0
- :address2,
0
- :address3,
0
- :phone,
0
- :fax
0
-
0
+ :country,
0
+ :postal_code,
0
+ :province,
0
+ :city,
0
+ :address1,
0
+ :address2,
0
+ :address3,
0
+ :phone,
0
+ :fax
0
+
0
       alias_method :zip, :postal_code
0
       alias_method :postal, :postal_code
0
       alias_method :state, :province
0
       alias_method :territory, :province
0
       alias_method :region, :province
0
-
0
+
0
       def initialize(options = {})
0
         @country = (options[:country].nil? or options[:country].is_a?(ActiveMerchant::Country)) ?
0
- options[:country] :
0
- ActiveMerchant::Country.find(options[:country])
0
+ options[:country] :
0
+ ActiveMerchant::Country.find(options[:country])
0
         @postal_code = options[:postal_code] || options[:postal] || options[:zip]
0
         @province = options[:province] || options[:state] || options[:territory] || options[:region]
0
         @city = options[:city]
0
@@ -32,9 +59,9 @@ module ActiveMerchant #:nodoc:
0
         @phone = options[:phone]
0
         @fax = options[:fax]
0
       end
0
-
0
+
0
       def self.from(object, options={})
0
- return object if object.is_a? ActiveMerchant::Shipping::Location
0
+ return object if object.is_a? self.class
0
         attr_mappings = {
0
           :country => [:country_code, :country],
0
           :postal_code => [:postal_code, :zip, :postal],
0
@@ -63,15 +90,15 @@ module ActiveMerchant #:nodoc:
0
         end
0
         self.new(attributes.update(options))
0
       end
0
-
0
+
0
       def country_code(format)
0
         @country.nil? ? nil : @country.code(format).first.value
0
       end
0
-
0
+
0
       def to_s
0
         prettyprint.gsub(/\n/, ' ')
0
       end
0
-
0
+
0
       def prettyprint
0
         chunks = []
0
         chunks << [@address1,@address2,@address3].reject {|e| e.blank?}.join("\n")
0
@@ -79,14 +106,31 @@ module ActiveMerchant #:nodoc:
0
         chunks << @country
0
         chunks.reject {|e| e.blank?}.join("\n")
0
       end
0
-
0
+
0
       def inspect
0
         string = prettyprint
0
         string << "\nPhone: #{@phone}" unless @phone.blank?
0
         string << "\nFax: #{@fax}" unless @fax.blank?
0
         string
0
       end
0
- end
0
       
0
+ def ==(obj)
0
+ obj.equal?(self) || (obj.instance_of?(self.class) &&
0
+ country == obj.country &&
0
+ postal_code == obj.postal_code &&
0
+ province == obj.province &&
0
+ city == obj.city &&
0
+ address1 == obj.address1 &&
0
+ address2 == obj.address2 &&
0
+ address3 == obj.address3 &&
0
+ phone == obj.phone &&
0
+ fax == obj.fax
0
+ )
0
+ end
0
+
0
+ def eql?(obj)
0
+ self == (obj)
0
+ end
0
+ end
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.