class Trim

Attributes

exterior[RW]
fuel_economy[RW]
interior[RW]
performance[RW]
trim_name[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

available_stats() click to toggle source
# 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() click to toggle source
# File lib/trim.rb, line 31
def city_range
  self.mpg_city * @fuel_economy.fuel_tank_capacity
end
engine() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/trim.rb, line 27
def highway_range
  self.mpg_highway * @fuel_economy.fuel_tank_capacity
end
mpg_city() click to toggle source
# 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() click to toggle source
# File lib/trim.rb, line 12
def mpg_combined
  (self.mpg_city + self.mpg_highway) / 2
end
mpg_highway() click to toggle source
# 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() click to toggle source
# File lib/trim.rb, line 63
def to_s
  @trim_name
end