Class: Flight
- Inherits:
-
Object
- Object
- Flight
- Defined in:
- lib/flight_radar/flight.rb
Overview
The Flight
class represents information about a flight obtained from a data source.
It provides methods to access and format various attributes related to the flight,
such as altitude, ground speed, heading, and more.
Constant Summary collapse
- DEFAULT_TEXT =
'N/A'
Instance Attribute Summary collapse
-
#id ⇒ Object
Accessor for the flight ID.
Instance Method Summary collapse
-
#altitude ⇒ String
Returns a formatted string representing the altitude of the flight.
-
#flight_level ⇒ String
Returns a formatted string representing the flight level based on altitude.
-
#ground_speed ⇒ String
Returns a formatted string representing the ground speed of the flight.
-
#heading ⇒ String
Returns a formatted string representing the heading of the flight.
-
#initialize(flight_id, info) ⇒ Flight
constructor
Initializes a new instance of the
Flight
class with the given flight ID and information. -
#to_s ⇒ String
Returns a string representation of the
Flight
object. -
#vertical_speed ⇒ String
Returns a formatted string representing the vertical speed of the flight.
Constructor Details
#initialize(flight_id, info) ⇒ Flight
Initializes a new instance of the Flight
class with the given flight ID and information.
rubocop:disable Metrics
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/flight_radar/flight.rb', line 19 def initialize(flight_id, info) @id = flight_id @icao_24bit = get_info(info[0]) @latitude = get_info(info[1]) @longitude = get_info(info[2]) @heading = get_info(info[3]) @altitude = get_info(info[4]) @ground_speed = get_info(info[5]) @squawk = get_info(info[6]) @aircraft_code = get_info(info[8]) @registration = get_info(info[9]) @time = get_info(info[10]) @origin_airport_iata = get_info(info[11]) @destination_airport_iata = get_info(info[12]) @number = get_info(info[13]) @airline_iata = get_info(info[13][0..1]) @on_ground = get_info(info[14]) @vertical_speed = get_info(info[15]) @callsign = get_info(info[16]) @airline_icao = get_info(info[18]) end |
Instance Attribute Details
#id ⇒ Object
Accessor for the flight ID.
10 11 12 |
# File 'lib/flight_radar/flight.rb', line 10 def id @id end |
Instance Method Details
#altitude ⇒ String
Returns a formatted string representing the altitude of the flight.
55 56 57 |
# File 'lib/flight_radar/flight.rb', line 55 def altitude "#{@altitude} ft" end |
#flight_level ⇒ String
Returns a formatted string representing the flight level based on altitude.
62 63 64 |
# File 'lib/flight_radar/flight.rb', line 62 def flight_level @altitude > 10_000 ? "#{@altitude[0..2]} FL" : altitude end |
#ground_speed ⇒ String
Returns a formatted string representing the ground speed of the flight.
69 70 71 72 73 |
# File 'lib/flight_radar/flight.rb', line 69 def ground_speed speed = "#{@ground_speed} kt" speed += 's' if @ground_speed > 1 speed end |
#heading ⇒ String
Returns a formatted string representing the heading of the flight.
78 79 80 |
# File 'lib/flight_radar/flight.rb', line 78 def heading "#{@heading}°" end |
#to_s ⇒ String
Returns a string representation of the Flight
object.
45 46 47 48 49 50 |
# File 'lib/flight_radar/flight.rb', line 45 def to_s "<(#{@aircraft_code}) #{@registration} - Altitude: #{@altitude} - Ground Speed: #{@ground_speed} - Heading: #{@ground_speed}>" end |
#vertical_speed ⇒ String
Returns a formatted string representing the vertical speed of the flight.
85 86 87 |
# File 'lib/flight_radar/flight.rb', line 85 def vertical_speed "#{@vertical_speed} fpm" end |