1 class Customer
< ActiveRecord
::Base
2 composed_of
:address, :mapping => [ %w(address_street street
), %w(address_city city
), %w(address_country country
) ], :allow_nil => true
3 composed_of
:balance, :class_name => "Money", :mapping => %w(balance amount
), :converter => Proc
.new
{ |balance
| balance
.to_money
}
4 composed_of
:gps_location, :allow_nil => true
5 composed_of
:fullname, :mapping => %w(name to_s
), :constructor => Proc
.new
{ |name
| Fullname
.parse(name
) }, :converter => :parse
9 attr_reader
:street, :city, :country
11 def initialize(street
, city
, country
)
12 @street, @city, @country = street
, city
, country
15 def close_to
?(other_address
)
16 city
== other_address
.city
&& country
== other_address
.country
20 other
.is_a
?(self.class) && other
.street
== street
&& other
.city
== city
&& other
.country
== country
25 attr_reader
:amount, :currency
27 EXCHANGE_RATES
= { "USD_TO_DKK" => 6, "DKK_TO_USD" => 0.6 }
29 def initialize(amount
, currency
= "USD")
30 @amount, @currency = amount
, currency
33 def exchange_to(other_currency
)
34 Money
.new((amount
* EXCHANGE_RATES
["#{currency}_TO_#{other_currency}"]).floor
, other_currency
)
39 attr_reader
:gps_location
41 def initialize(gps_location
)
42 @gps_location = gps_location
46 gps_location
.split("x").first
50 gps_location
.split("x").last
54 self.latitude
== other
.latitude
&& self.longitude
== other
.longitude
59 attr_reader
:first, :last
66 def initialize(first
, last
= nil)
67 @first, @last = first
, last
71 "#{first} #{last.upcase}"