Class: Trim
- Inherits:
-
Object
- Object
- Trim
- Defined in:
- lib/trim.rb
Instance Attribute Summary collapse
-
#exterior ⇒ Object
Returns the value of attribute exterior.
-
#fuel_economy ⇒ Object
Returns the value of attribute fuel_economy.
-
#interior ⇒ Object
Returns the value of attribute interior.
-
#performance ⇒ Object
Returns the value of attribute performance.
-
#trim_name ⇒ Object
Returns the value of attribute trim_name.
Instance Method Summary collapse
- #available_stats ⇒ Object
- #city_range ⇒ Object
- #engine ⇒ Object
- #get_stat(type) ⇒ Object
- #highway_range ⇒ Object
-
#initialize ⇒ Trim
constructor
A new instance of Trim.
- #mpg_city ⇒ Object
- #mpg_combined ⇒ Object
- #mpg_highway ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Trim
Returns a new instance of Trim.
4 5 6 7 8 9 |
# File 'lib/trim.rb', line 4 def initialize() @exterior = Struct::ExteriorStats.new @interior = Struct::InteriorStats.new @performance = Struct::PerformanceStats.new @fuel_economy = Struct::FuelEconomyStats.new end |
Instance Attribute Details
#exterior ⇒ Object
Returns the value of attribute exterior.
2 3 4 |
# File 'lib/trim.rb', line 2 def exterior @exterior end |
#fuel_economy ⇒ Object
Returns the value of attribute fuel_economy.
2 3 4 |
# File 'lib/trim.rb', line 2 def fuel_economy @fuel_economy end |
#interior ⇒ Object
Returns the value of attribute interior.
2 3 4 |
# File 'lib/trim.rb', line 2 def interior @interior end |
#performance ⇒ Object
Returns the value of attribute performance.
2 3 4 |
# File 'lib/trim.rb', line 2 def performance @performance end |
#trim_name ⇒ Object
Returns the value of attribute trim_name.
2 3 4 |
# File 'lib/trim.rb', line 2 def trim_name @trim_name end |
Instance Method Details
#available_stats ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/trim.rb', line 42 def available_stats @performance.members.each do |stat_name| unless @performance[stat_name].nil?;puts "performance.#{stat_name.to_s}"end end @interior.members.each do |stat_name| unless @interior[stat_name].nil?;puts "interior.#{stat_name.to_s}"end end @exterior.members.each do |stat_name| unless @exterior[stat_name].nil?;puts "exterior.#{stat_name.to_s}"end end @fuel_economy.members.each do |stat_name| unless @fuel_economy[stat_name].nil?;puts "fuel_economy.#{stat_name.to_s}"end end end |
#city_range ⇒ Object
31 32 33 |
# File 'lib/trim.rb', line 31 def city_range self.mpg_city * @fuel_economy.fuel_tank_capacity end |
#engine ⇒ Object
58 59 60 61 |
# File 'lib/trim.rb', line 58 def engine puts "#{@performance.base_engine_size} #{@performance.base_engine_type} - with #{@performance.horsepower} at #{@performance.horsepower_rpm}rpm" + " and #{@performance.torque} of torque at #{@performance.torque_rpm}rpm" end |
#get_stat(type) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/trim.rb', line 35 def get_stat(type) if @performance.members.include? type.to_sym; return @performance[type]; end if @interior.members.include? type.to_sym; return @interior[type]; end if @exterior.members.include? type.to_sym; return @exterior[type]; end if @fuel_economy.members.include? type.to_sym; return @fuel_economy[type]; end end |
#highway_range ⇒ Object
27 28 29 |
# File 'lib/trim.rb', line 27 def highway_range self.mpg_highway * @fuel_economy.fuel_tank_capacity end |
#mpg_city ⇒ Object
16 17 18 19 |
# File 'lib/trim.rb', line 16 def mpg_city divider_index = @fuel_economy.epa_mileage_estimates.index('C') Integer(@fuel_economy.epa_mileage_estimates[0..divider_index-1]) end |
#mpg_combined ⇒ Object
12 13 14 |
# File 'lib/trim.rb', line 12 def mpg_combined (self.mpg_city + self.mpg_highway) / 2 end |
#mpg_highway ⇒ Object
21 22 23 24 25 |
# File 'lib/trim.rb', line 21 def mpg_highway divider_index = @fuel_economy.epa_mileage_estimates.index("/") + 1 end_index = @fuel_economy.epa_mileage_estimates.index('H') Integer(@fuel_economy.epa_mileage_estimates[divider_index..end_index-1].strip) end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/trim.rb', line 63 def to_s @trim_name end |