earth 0.12.2 → 0.12.3

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.
@@ -49,6 +49,18 @@ class AutomobileFuel < ActiveRecord::Base
49
49
  end
50
50
  end
51
51
 
52
+ # for AutomobileMakeModel.custom_find
53
+ def suffix
54
+ case code
55
+ when 'D', 'BP-B5', 'BP-B20', 'BP-B100'
56
+ 'DIESEL'
57
+ when 'E'
58
+ 'FFV'
59
+ when 'C'
60
+ 'CNG'
61
+ end
62
+ end
63
+
52
64
  falls_back_on :name => 'fallback',
53
65
  :base_fuel_name => 'Motor Gasoline',
54
66
  :blend_fuel_name => 'Distillate Fuel Oil No. 2',
@@ -5,6 +5,19 @@ class AutomobileMakeModel < ActiveRecord::Base
5
5
  belongs_to :automobile_fuel, :foreign_key => :fuel_code, :primary_key => :code
6
6
  belongs_to :alt_automobile_fuel, :foreign_key => :alt_fuel_code, :primary_key => :code, :class_name => 'AutomobileFuel'
7
7
 
8
+ # Used by Automobile and AutomobileTrip to look up a make model year considering fuel
9
+ def self.custom_find(characteristics)
10
+ if characteristics[:make] and characteristics[:model]
11
+ # append fuel suffix to model name and search
12
+ make_model = if characteristics[:automobile_fuel]
13
+ find_by_make_name_and_model_name characteristics[:make].name, [characteristics[:model].name, characteristics[:automobile_fuel].suffix].join(' ')
14
+ end
15
+
16
+ # use original model name if fuel suffix didn't help
17
+ make_model ? make_model : AutomobileMakeModel.find_by_make_name_and_model_name(characteristics[:make].name, characteristics[:model].name)
18
+ end
19
+ end
20
+
8
21
  # for deriving fuel codes and type name
9
22
  def model_years
10
23
  AutomobileMakeModelYear.where(:make_name => make_name, :model_name => model_name)
@@ -1,3 +1,3 @@
1
1
  module Earth
2
- VERSION = "0.12.2"
2
+ VERSION = "0.12.3"
3
3
  end
@@ -68,6 +68,46 @@ describe AutomobileMakeModel do
68
68
  it { f150_ffv.type_name.should == 'Light-duty trucks' }
69
69
  end
70
70
 
71
+ describe '.custom_find' do
72
+ it 'considers fuel' do
73
+ %w{ diesel B5 B20 B100 }.each do |fuel|
74
+ AMM.custom_find(
75
+ {
76
+ :make => AutomobileMake.find('Volkswagen'),
77
+ :model => AutomobileModel.find('Jetta'),
78
+ :automobile_fuel => AutomobileFuel.find(fuel)
79
+ }
80
+ ).name.should == 'Volkswagen JETTA DIESEL'
81
+ end
82
+
83
+ AMM.custom_find(
84
+ {
85
+ :make => AutomobileMake.find('Ford'),
86
+ :model => AutomobileModel.find('F150'),
87
+ :automobile_fuel => AutomobileFuel.find('E85')
88
+ }
89
+ ).name.should == 'Ford F150 FFV'
90
+
91
+ AMM.custom_find(
92
+ {
93
+ :make => AutomobileMake.find('Honda'),
94
+ :model => AutomobileModel.find('Civic'),
95
+ :automobile_fuel => AutomobileFuel.find('CNG')
96
+ }
97
+ ).name.should == 'Honda CIVIC CNG'
98
+ end
99
+
100
+ it 'ignores fuel if it does not help' do
101
+ AMM.custom_find(
102
+ {
103
+ :make => AutomobileMake.find('Volkswagen'),
104
+ :model => AutomobileModel.find('Jetta'),
105
+ :automobile_fuel => AutomobileFuel.find('CNG')
106
+ }
107
+ ).name.should == 'Volkswagen JETTA'
108
+ end
109
+ end
110
+
71
111
  describe '#model_years' do
72
112
  it { civic.model_years.sort.should == civic_years.sort }
73
113
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.12.2
5
+ version: 0.12.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seamus Abshere
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2012-06-15 00:00:00 Z
15
+ date: 2012-06-20 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -681,7 +681,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
681
681
  requirements:
682
682
  - - ">="
683
683
  - !ruby/object:Gem::Version
684
- hash: 2577779194019475364
684
+ hash: -307877030326161721
685
685
  segments:
686
686
  - 0
687
687
  version: "0"
@@ -690,7 +690,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
690
690
  requirements:
691
691
  - - ">="
692
692
  - !ruby/object:Gem::Version
693
- hash: 2577779194019475364
693
+ hash: -307877030326161721
694
694
  segments:
695
695
  - 0
696
696
  version: "0"