Class: Energy::Flight

Inherits:
Consumer show all
Defined in:
lib/energy/flight.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Flight

:nodoc:



17
18
19
20
21
22
23
24
# File 'lib/energy/flight.rb', line 17

def initialize(attrs = {}) # :nodoc:
  attrs = attrs.symbolize_keys
  @airline = attrs[:airline]
  @aircraft = attrs[:aircraft]
  @origin_airport = attrs[:origin_airport]
  @destination_airport = attrs[:destination_airport]
  @segments_per_trip = attrs[:segments_per_trip] || 1
end

Instance Attribute Details

#aircraftObject

Returns the value of attribute aircraft.



4
5
6
# File 'lib/energy/flight.rb', line 4

def aircraft
  @aircraft
end

#airlineObject

Returns the value of attribute airline.



3
4
5
# File 'lib/energy/flight.rb', line 3

def airline
  @airline
end

#destination_airportObject

Returns the value of attribute destination_airport.



6
7
8
# File 'lib/energy/flight.rb', line 6

def destination_airport
  @destination_airport
end

#origin_airportObject

Returns the value of attribute origin_airport.



5
6
7
# File 'lib/energy/flight.rb', line 5

def origin_airport
  @origin_airport
end

#segments_per_tripObject

Returns the value of attribute segments_per_trip.



7
8
9
# File 'lib/energy/flight.rb', line 7

def segments_per_trip
  @segments_per_trip
end

Class Method Details

.fuel_efficiency(attrs = {}) ⇒ Object

Estimate the fuel efficiency (length / volume, not taking into account passengers) of a flight given any of the following optional characteristics:

  • airline - “american eagle”

  • aircraft - “b747”

  • origin_airport - “msn”

  • destination_airport - “iah”

  • segments_per_trip - 1 (defaults to 1 to force calculation as a one-segment trip)

See carbon.brighterplanet.com/models/flight for more details



45
46
47
48
49
# File 'lib/energy/flight.rb', line 45

def fuel_efficiency(attrs = {})
  d = estimate(:distance, attrs)
  f = estimate(:fuel_use, attrs)
  d / f
end

.fuel_use(attrs = {}) ⇒ Object

Estimate the fuel used by a flight given any of the following optional characteristics:

  • airline - “american eagle”

  • aircraft - “b747”

  • origin_airport - “msn”

  • destination_airport - “iah”

  • segments_per_trip - 1 (defaults to 1 to force calculation as a one-segment trip)

See carbon.brighterplanet.com/models/flight for more details



34
35
36
# File 'lib/energy/flight.rb', line 34

def fuel_use(attrs = {})
  estimate :fuel_use, attrs
end