Class: Energy::Flight
Instance Attribute Summary collapse
-
#aircraft ⇒ Object
Returns the value of attribute aircraft.
-
#airline ⇒ Object
Returns the value of attribute airline.
-
#destination_airport ⇒ Object
Returns the value of attribute destination_airport.
-
#origin_airport ⇒ Object
Returns the value of attribute origin_airport.
-
#segments_per_trip ⇒ Object
Returns the value of attribute segments_per_trip.
Class Method Summary collapse
-
.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. -
.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.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Flight
constructor
:nodoc:.
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
#aircraft ⇒ Object
Returns the value of attribute aircraft.
4 5 6 |
# File 'lib/energy/flight.rb', line 4 def aircraft @aircraft end |
#airline ⇒ Object
Returns the value of attribute airline.
3 4 5 |
# File 'lib/energy/flight.rb', line 3 def airline @airline end |
#destination_airport ⇒ Object
Returns the value of attribute destination_airport.
6 7 8 |
# File 'lib/energy/flight.rb', line 6 def destination_airport @destination_airport end |
#origin_airport ⇒ Object
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_trip ⇒ Object
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 |