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
-
#aircraft_code ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#airline_iata ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#airline_icao ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#callsign ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#destination_airport_iata ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#icao_24bit ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#id ⇒ Object
Accessor for the flight ID.
-
#latitude ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#longitude ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#number ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#on_ground ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#origin_airport_iata ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#registration ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#squawk ⇒ Object
readonly
Read-only accessors for flight attributes.
-
#time ⇒ Object
readonly
Read-only accessors for flight attributes.
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
Flightclass with the given flight ID and information. -
#to_s ⇒ String
Returns a string representation of the
Flightobject. -
#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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/flight_radar/flight.rb', line 25 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 = @number != DEFAULT_TEXT && @number.length >= 2 ? @number[0..1] : DEFAULT_TEXT @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
#aircraft_code ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def aircraft_code @aircraft_code end |
#airline_iata ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def airline_iata @airline_iata end |
#airline_icao ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def airline_icao @airline_icao end |
#callsign ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def callsign @callsign end |
#destination_airport_iata ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def destination_airport_iata @destination_airport_iata end |
#icao_24bit ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def icao_24bit @icao_24bit end |
#id ⇒ Object
Accessor for the flight ID.
10 11 12 |
# File 'lib/flight_radar/flight.rb', line 10 def id @id end |
#latitude ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def latitude @latitude end |
#longitude ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def longitude @longitude end |
#number ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def number @number end |
#on_ground ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def on_ground @on_ground end |
#origin_airport_iata ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def origin_airport_iata @origin_airport_iata end |
#registration ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def registration @registration end |
#squawk ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def squawk @squawk end |
#time ⇒ Object (readonly)
Read-only accessors for flight attributes.
13 14 15 |
# File 'lib/flight_radar/flight.rb', line 13 def time @time end |
Instance Method Details
#altitude ⇒ String
Returns a formatted string representing the altitude of the flight.
61 62 63 |
# File 'lib/flight_radar/flight.rb', line 61 def altitude "#{@altitude} ft" end |
#flight_level ⇒ String
Returns a formatted string representing the flight level based on altitude.
68 69 70 71 72 |
# File 'lib/flight_radar/flight.rb', line 68 def flight_level return altitude if @altitude == DEFAULT_TEXT || @altitude.to_i <= 10_000 "FL#{(@altitude.to_i / 100).to_s.rjust(3, '0')}" end |
#ground_speed ⇒ String
Returns a formatted string representing the ground speed of the flight.
77 78 79 80 81 82 83 84 |
# File 'lib/flight_radar/flight.rb', line 77 def ground_speed return "#{@ground_speed} kt" if @ground_speed == DEFAULT_TEXT speed_value = @ground_speed.to_i speed = "#{speed_value} kt" speed += 's' if speed_value > 1 speed end |
#heading ⇒ String
Returns a formatted string representing the heading of the flight.
89 90 91 |
# File 'lib/flight_radar/flight.rb', line 89 def heading "#{@heading}°" end |
#to_s ⇒ String
Returns a string representation of the Flight object.
51 52 53 54 55 56 |
# File 'lib/flight_radar/flight.rb', line 51 def to_s "<(#{@aircraft_code}) #{@registration} - Altitude: #{@altitude} - Ground Speed: #{@ground_speed} - Heading: #{@heading}>" end |
#vertical_speed ⇒ String
Returns a formatted string representing the vertical speed of the flight.
96 97 98 |
# File 'lib/flight_radar/flight.rb', line 96 def vertical_speed "#{@vertical_speed} fpm" end |