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.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#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.
- #ship_type_human ⇒ Object
- #status_human ⇒ Object
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 31 |
# 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"] @timestamp = 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"] @width = attributes["width"] @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 @timestamp end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/marinetraffic/vessel.rb', line 5 def width @width 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, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/marinetraffic/vessel.rb', line 33 def self.find(mmsi, extended = false, = {}) params = { mmsi: mmsi, timespan: 20 }.merge() params[:msgtype] = :extended if extended response = API.call(:exportvessel, params) result = response.xpath("//row")[0] if result != nil attributes = map_attributes(response.xpath("//row")[0], extended) new(attributes) end end |
.map_attributes(response, extended) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/marinetraffic/vessel.rb', line 45 def self.map_attributes(response, extended) attributes = {} attributes["mmsi"] = response['MMSI'] attributes["lat"] = response['LAT'].to_f attributes["lon"] = response['LON'].to_f attributes["speed"] = response['SPEED'].to_i attributes["course"] = response['COURSE'].to_i if extended attributes["timestamp"] = response['TIMESTAMP'] attributes["ship_name"] = response['SHIPNAME'] attributes["ship_type"] = response['SHIPTYPE'].to_i attributes["imo"] = response['IMO'] attributes["callsign"] = response['CALLSIGN'] attributes["flag"] = response['FLAG'] attributes["current_port"] = response['CURRENT_PORT'] attributes["last_port"] = response['LAST_PORT'] attributes["last_port_time"] = response['LAST_PORT_TIME'] attributes["destination"] = response['DESTINATION'] attributes["eta"] = response['ETA'] attributes["length"] = response['LENGTH'].to_i attributes["width"] = response['WIDTH'].to_i attributes["draught"] = response['DRAUGHT'].to_i attributes["grt"] = response['GRT'].to_i attributes["dwt"] = response['DWT'].to_i attributes["year_built"] = response['YEAR_BUILT'].to_i else attributes["status"] = response['STATUS'].to_i attributes["timestamp"] = response['TIMESTAMP'] end attributes end |
Instance Method Details
#ship_type_human ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/marinetraffic/vessel.rb', line 116 def ship_type_human return if ship_type == nil case ship_type.to_s[0].to_i when 1 'Reserved' when 2 'Wing In Ground' when 3 'Special Category' when 4 'High-Speed Craft' when 5 'Special Category' when 6 'Passenger' when 7 'Cargo' when 8 'Tanker' when 9 'Other' end end |
#status_human ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/marinetraffic/vessel.rb', line 78 def status_human case status when 0 'under way using engine' when 1 'at anchor' when 2 'not under command ' when 3 'restricted maneuverability' when 4 'constrained by her draught' when 5 'moored' when 6 'aground ' when 7 'engaged in fishing' when 8 'under way sailing' when 9 'reserved for future amendment of navigational status for ships carrying DG, HS, or MP, or IMO hazard or pollutant category C, high-speed craft (HSC)' when 10 'reserved for future amendment of navigational status for ships carrying dangerous goods (DG), harmful substances (HS) or marine pollutants (MP), or IMO hazard or pollutant category A, wing in ground (WIG)' when 11 'power-driven vessel towing astern (regional use)' when 12 'power-driven vessel pushing ahead or towing alongside (regional use)' when 13 'reserved for future use' when 14 'AIS-SART (active), MOB-AIS, EPIRB-AIS' when 15 'undefined = default (also used by AIS-SART, MOB-AIS and EPIRB-AIS under test)' end end |