Class: JetBluePlaneTracker::Airport
- Inherits:
-
Object
- Object
- JetBluePlaneTracker::Airport
- Defined in:
- lib/jetblue_plane_tracker/airport.rb
Instance Attribute Summary collapse
-
#altitude ⇒ Object
Returns the value of attribute altitude.
-
#city ⇒ Object
Returns the value of attribute city.
-
#country ⇒ Object
Returns the value of attribute country.
-
#dst ⇒ Object
Returns the value of attribute dst.
-
#iata ⇒ Object
Returns the value of attribute iata.
-
#icao ⇒ Object
Returns the value of attribute icao.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#name ⇒ Object
Returns the value of attribute name.
-
#timezone ⇒ Object
Returns the value of attribute timezone.
Class Method Summary collapse
- .all ⇒ Object
- .find_by_iata(iata_code) ⇒ Object
- .get_json ⇒ Object
- .new_object_instance(airport_data) ⇒ Object
- .parse_airport_iata(airport_name) ⇒ Object
- .search(search_text) ⇒ Object
Instance Method Summary collapse
-
#initialize(iata, icao, name, city, country, latitude, longitude, altitude, timezone, dst) ⇒ Airport
constructor
A new instance of Airport.
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(iata, icao, name, city, country, latitude, longitude, altitude, timezone, dst) ⇒ Airport
Returns a new instance of Airport.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 7 def initialize(iata, icao, name, city, country, latitude, longitude, altitude, timezone, dst) self.iata = iata self.icao = icao self.name = name self.city = city self.country = country self.longitude = longitude.to_f self.latitude = latitude.to_f self.altitude = altitude self.timezone = timezone self.dst = dst end |
Instance Attribute Details
#altitude ⇒ Object
Returns the value of attribute altitude.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def altitude @altitude end |
#city ⇒ Object
Returns the value of attribute city.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def city @city end |
#country ⇒ Object
Returns the value of attribute country.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def country @country end |
#dst ⇒ Object
Returns the value of attribute dst.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def dst @dst end |
#iata ⇒ Object
Returns the value of attribute iata.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def iata @iata end |
#icao ⇒ Object
Returns the value of attribute icao.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def icao @icao end |
#latitude ⇒ Object
Returns the value of attribute latitude.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def name @name end |
#timezone ⇒ Object
Returns the value of attribute timezone.
5 6 7 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 5 def timezone @timezone end |
Class Method Details
.all ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 67 def all data = get_json airports = [] data.each do |airport_data| airports << new_object_instance(airport_data[1]) end airports end |
.find_by_iata(iata_code) ⇒ Object
51 52 53 54 55 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 51 def find_by_iata(iata_code) data = get_json airport_data = data[iata_code] new_object_instance(airport_data) end |
.get_json ⇒ Object
76 77 78 79 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 76 def get_json file = File.read(File.('../../data/airports.json', __FILE__)) JSON.parse(file) end |
.new_object_instance(airport_data) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 81 def new_object_instance(airport_data) new(airport_data["iata"], airport_data["icao"], airport_data["name"], airport_data["city"], airport_data["country"], airport_data["latitude"], airport_data["longitude"], airport_data["altitude"], airport_data["timezone"], airport_data["dst"]) end |
.parse_airport_iata(airport_name) ⇒ Object
47 48 49 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 47 def parse_airport_iata(airport_name) airport_name[/[(][a-zA-Z]*[)]/, 0].gsub(/[()]/, "").strip.to_s end |
.search(search_text) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 57 def search(search_text) data = get_json airports = [] data.each do |d| airport_data = d[1] airports << new_object_instance(airport_data) if airport_data.has_value?(search_text) end airports end |
Instance Method Details
#to_json ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 30 def to_json { iata: self.iata, icao: self.icao, name: self.name, city: self.city, country: self.country, latitude: self.latitude, longitude: self.longitude, altitude: self.altitude, timezone: self.timezone, dst: self.dst } end |
#to_s ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/jetblue_plane_tracker/airport.rb', line 20 def to_s str = "" self.instance_variables.each do |var| name = var.to_s.gsub!("@", "") key = send(name) str += "#{name}: #{key}, " end str[0..str.length-3] end |