Class: Marinetraffic::Vessel

Inherits:
Object
  • Object
show all
Defined in:
lib/marinetraffic/vessel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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"]
  @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"]
  @draught = attributes["draught"]
  @grt = attributes["grt"]
  @dwt = attributes["dwt"]
  @year_built = attributes["year_built"]
end

Instance Attribute Details

#callsignObject (readonly)

Returns the value of attribute callsign.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def callsign
  @callsign
end

#courseObject (readonly)

Returns the value of attribute course.



4
5
6
# File 'lib/marinetraffic/vessel.rb', line 4

def course
  @course
end

#current_portObject (readonly)

Returns the value of attribute current_port.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def current_port
  @current_port
end

#destinationObject (readonly)

Returns the value of attribute destination.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def destination
  @destination
end

#draughtObject (readonly)

Returns the value of attribute draught.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def draught
  @draught
end

#dwtObject (readonly)

Returns the value of attribute dwt.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def dwt
  @dwt
end

#etaObject (readonly)

Returns the value of attribute eta.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def eta
  @eta
end

#flagObject (readonly)

Returns the value of attribute flag.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def flag
  @flag
end

#grtObject (readonly)

Returns the value of attribute grt.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def grt
  @grt
end

#imoObject (readonly)

Returns the value of attribute imo.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def imo
  @imo
end

#last_portObject (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_timeObject (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

#latObject (readonly)

Returns the value of attribute lat.



4
5
6
# File 'lib/marinetraffic/vessel.rb', line 4

def lat
  @lat
end

#lengthObject (readonly)

Returns the value of attribute length.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def length
  @length
end

#lonObject (readonly)

Returns the value of attribute lon.



4
5
6
# File 'lib/marinetraffic/vessel.rb', line 4

def lon
  @lon
end

#mmsiObject (readonly)

Returns the value of attribute mmsi.



4
5
6
# File 'lib/marinetraffic/vessel.rb', line 4

def mmsi
  @mmsi
end

#ship_nameObject (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_typeObject (readonly)

Returns the value of attribute ship_type.



5
6
7
# File 'lib/marinetraffic/vessel.rb', line 5

def ship_type
  @ship_type
end

#speedObject (readonly)

Returns the value of attribute speed.



4
5
6
# File 'lib/marinetraffic/vessel.rb', line 4

def speed
  @speed
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/marinetraffic/vessel.rb', line 4

def status
  @status
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



4
5
6
# File 'lib/marinetraffic/vessel.rb', line 4

def timestamp
  @timestamp
end

#year_builtObject (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