Class: Marinetraffic::Vessel
- Inherits:
-
Object
- Object
- Marinetraffic::Vessel
- Defined in:
- lib/marinetraffic/vessel.rb
Instance Attribute Summary collapse
-
#callsign ⇒ Object
readonly
Returns the value of attribute callsign.
-
#course ⇒ Object
readonly
Returns the value of attribute course.
-
#current_port ⇒ Object
readonly
Returns the value of attribute current_port.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#draught ⇒ Object
readonly
Returns the value of attribute draught.
-
#dwt ⇒ Object
readonly
Returns the value of attribute dwt.
-
#eta ⇒ Object
readonly
Returns the value of attribute eta.
-
#flag ⇒ Object
readonly
Returns the value of attribute flag.
-
#grt ⇒ Object
readonly
Returns the value of attribute grt.
-
#imo ⇒ Object
readonly
Returns the value of attribute imo.
-
#last_port ⇒ Object
readonly
Returns the value of attribute last_port.
-
#last_port_time ⇒ Object
readonly
Returns the value of attribute last_port_time.
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#lon ⇒ Object
readonly
Returns the value of attribute lon.
-
#mmsi ⇒ Object
readonly
Returns the value of attribute mmsi.
-
#ship_name ⇒ Object
readonly
Returns the value of attribute ship_name.
-
#ship_type ⇒ Object
readonly
Returns the value of attribute ship_type.
-
#speed ⇒ Object
readonly
Returns the value of attribute speed.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#year_built ⇒ Object
readonly
Returns the value of attribute year_built.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Vessel
constructor
A new instance of Vessel.
Constructor Details
#initialize(attributes = {}) ⇒ Vessel
Returns a new instance of Vessel.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/marinetraffic/vessel.rb', line 7 def initialize(attributes = {}) @mmsi = attributes["mmsi"] @lat = attributes["lat"] @lon = attributes["lon"] @speed = attributes["speed"] @course = attributes["course"] @status = attributes["status"] = attributes["timestamp"] @ship_type = attributes["ship_type"] @ship_name = attributes["ship_name"] @imo = attributes["imo"] @callsign = attributes["callsign"] @flag = attributes["flag"] @current_port = attributes["current_port"] @last_port = attributes["last_port"] @last_port_time = attributes["last_port_time"] @destination = attributes["destination"] @eta = attributes["eta"] @length = attributes["length"] @draught = attributes["draught"] @grt = attributes["grt"] @dwt = attributes["dwt"] @year_built = attributes["year_built"] end |
Instance Attribute Details
#callsign ⇒ Object (readonly)
Returns the value of attribute callsign.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def callsign @callsign end |
#course ⇒ Object (readonly)
Returns the value of attribute course.
4 5 6 |
# File 'lib/marinetraffic/vessel.rb', line 4 def course @course end |
#current_port ⇒ Object (readonly)
Returns the value of attribute current_port.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def current_port @current_port end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def destination @destination end |
#draught ⇒ Object (readonly)
Returns the value of attribute draught.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def draught @draught end |
#dwt ⇒ Object (readonly)
Returns the value of attribute dwt.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def dwt @dwt end |
#eta ⇒ Object (readonly)
Returns the value of attribute eta.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def eta @eta end |
#flag ⇒ Object (readonly)
Returns the value of attribute flag.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def flag @flag end |
#grt ⇒ Object (readonly)
Returns the value of attribute grt.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def grt @grt end |
#imo ⇒ Object (readonly)
Returns the value of attribute imo.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def imo @imo end |
#last_port ⇒ Object (readonly)
Returns the value of attribute last_port.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def last_port @last_port end |
#last_port_time ⇒ Object (readonly)
Returns the value of attribute last_port_time.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def last_port_time @last_port_time end |
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
4 5 6 |
# File 'lib/marinetraffic/vessel.rb', line 4 def lat @lat end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def length @length end |
#lon ⇒ Object (readonly)
Returns the value of attribute lon.
4 5 6 |
# File 'lib/marinetraffic/vessel.rb', line 4 def lon @lon end |
#mmsi ⇒ Object (readonly)
Returns the value of attribute mmsi.
4 5 6 |
# File 'lib/marinetraffic/vessel.rb', line 4 def mmsi @mmsi end |
#ship_name ⇒ Object (readonly)
Returns the value of attribute ship_name.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def ship_name @ship_name end |
#ship_type ⇒ Object (readonly)
Returns the value of attribute ship_type.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def ship_type @ship_type end |
#speed ⇒ Object (readonly)
Returns the value of attribute speed.
4 5 6 |
# File 'lib/marinetraffic/vessel.rb', line 4 def speed @speed end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/marinetraffic/vessel.rb', line 4 def status @status end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/marinetraffic/vessel.rb', line 4 def end |
#year_built ⇒ Object (readonly)
Returns the value of attribute year_built.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def year_built @year_built end |
Class Method Details
.find(mmsi, extended = false) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/marinetraffic/vessel.rb', line 32 def self.find(mmsi, extended = false) params = { mmsi: mmsi, timespan: 20 } params[:msgtype] = :extended if extended response = API.call(:exportvessel, params) list = JSON.parse(response.body).first attributes = map_attributes(list) new(attributes) end |
.map_attributes(list) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/marinetraffic/vessel.rb', line 41 def self.map_attributes(list) attributes = {} attributes["mmsi"] = list.shift attributes["lat"] = list.shift attributes["lon"] = list.shift attributes["speed"] = list.shift attributes["course"] = list.shift attributes["status"] = list.shift attributes["timestamp"] = list.shift attributes["ship_type"] = list.shift attributes["ship_name"] = list.shift attributes["imo"] = list.shift attributes["callsign"] = list.shift attributes["flag"] = list.shift attributes["current_port"] = list.shift attributes["last_port"] = list.shift attributes["last_port_time"] = list.shift attributes["destination"] = list.shift attributes["eta"] = list.shift attributes["length"] = list.shift attributes["draught"] = list.shift attributes["grt"] = list.shift attributes["dwt"] = list.shift attributes["year_built"] = list.shift attributes end |