Froze rails gems
[depot.git] / vendor / rails / activerecord / test / models / customer.rb
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
6 end
7
8 class Address
9 attr_reader :street, :city, :country
10
11 def initialize(street, city, country)
12 @street, @city, @country = street, city, country
13 end
14
15 def close_to?(other_address)
16 city == other_address.city && country == other_address.country
17 end
18
19 def ==(other)
20 other.is_a?(self.class) && other.street == street && other.city == city && other.country == country
21 end
22 end
23
24 class Money
25 attr_reader :amount, :currency
26
27 EXCHANGE_RATES = { "USD_TO_DKK" => 6, "DKK_TO_USD" => 0.6 }
28
29 def initialize(amount, currency = "USD")
30 @amount, @currency = amount, currency
31 end
32
33 def exchange_to(other_currency)
34 Money.new((amount * EXCHANGE_RATES["#{currency}_TO_#{other_currency}"]).floor, other_currency)
35 end
36 end
37
38 class GpsLocation
39 attr_reader :gps_location
40
41 def initialize(gps_location)
42 @gps_location = gps_location
43 end
44
45 def latitude
46 gps_location.split("x").first
47 end
48
49 def longitude
50 gps_location.split("x").last
51 end
52
53 def ==(other)
54 self.latitude == other.latitude && self.longitude == other.longitude
55 end
56 end
57
58 class Fullname
59 attr_reader :first, :last
60
61 def self.parse(str)
62 return nil unless str
63 new(*str.to_s.split)
64 end
65
66 def initialize(first, last = nil)
67 @first, @last = first, last
68 end
69
70 def to_s
71 "#{first} #{last.upcase}"
72 end
73 end