Class: Trim

Inherits:
Object
  • Object
show all
Defined in:
lib/trim.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrim

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

#exteriorObject

Returns the value of attribute exterior.



2
3
4
# File 'lib/trim.rb', line 2

def exterior
  @exterior
end

#fuel_economyObject

Returns the value of attribute fuel_economy.



2
3
4
# File 'lib/trim.rb', line 2

def fuel_economy
  @fuel_economy
end

#interiorObject

Returns the value of attribute interior.



2
3
4
# File 'lib/trim.rb', line 2

def interior
  @interior
end

#performanceObject

Returns the value of attribute performance.



2
3
4
# File 'lib/trim.rb', line 2

def performance
  @performance
end

#trim_nameObject

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_statsObject



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_rangeObject



31
32
33
# File 'lib/trim.rb', line 31

def city_range
  self.mpg_city * @fuel_economy.fuel_tank_capacity
end

#engineObject



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_rangeObject



27
28
29
# File 'lib/trim.rb', line 27

def highway_range
  self.mpg_highway * @fuel_economy.fuel_tank_capacity
end

#mpg_cityObject



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_combinedObject



12
13
14
# File 'lib/trim.rb', line 12

def mpg_combined
  (self.mpg_city + self.mpg_highway) / 2
end

#mpg_highwayObject



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_sObject



63
64
65
# File 'lib/trim.rb', line 63

def to_s
  @trim_name
end