pla 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aae56ee6e048b9a588f913223ea882f5e577cd02
4
- data.tar.gz: c887b5cde11e4cde6ee833a2aa59ff41cdbdb7f0
3
+ metadata.gz: a6ff26195cda03de8489dfa3bed93742008759fc
4
+ data.tar.gz: ce5325c8586cc7bcd5724f35680fae04eaa8d4e2
5
5
  SHA512:
6
- metadata.gz: 94b36aa30506420c922153951efce3d49044aa140c0af6959bd3a4413aae69f04c6e2ee6d4049919a75384edd1c54bf5f78cd19d1353c2d5bee080508a201623
7
- data.tar.gz: 7198c2c6d800a1914302cb07496459903da5720d7704e829c69d2370a7980bdfb6216a1d8ec5fa6ce2d5e63248f7f11f94e6478623d524549c2a67b94ac36687
6
+ metadata.gz: aee1d6bc76d3715cdff4dd8e45f815b82ec2ba3f0e5fd3a179979bd42c101752dffd2f39590b29797b78f2c8225caa3e4dc55c52022815410e828ba5a612a36d
7
+ data.tar.gz: 9d908c1af6c73deff77aca7ac8c02db2e56ac136bdac3804c3dd717cc037bc4023c847383007a578bb37c6995ebaeafcde7d23bae9147b1203328b44e5f9f324
@@ -1,6 +1,4 @@
1
- require 'iso_country_codes'
2
-
3
- require 'pla/ship'
1
+ require 'pla/vessel'
4
2
 
5
3
  class PLA
6
4
  class Movement
@@ -11,8 +9,7 @@ class PLA
11
9
 
12
10
  def to_h
13
11
  normalise_timestamp!
14
- normalise_ship!
15
- normalise_country!
12
+ normalise_vessel!
16
13
  normalise_fields!
17
14
 
18
15
  @record
@@ -39,21 +36,12 @@ class PLA
39
36
  @record[:timestamp] = date
40
37
  end
41
38
 
42
- def normalise_ship!
39
+ def normalise_vessel!
43
40
  name = @record.delete(:'vessel name')
44
- @record[:vessel] = PLA::Ship.new(name).to_h
45
- end
46
-
47
- def normalise_country!
48
- country_code = @record.delete(:nationality)
49
- begin
50
- country = IsoCountryCodes.find(country_code).name
51
- rescue IsoCountryCodes::UnknownCodeError
52
- STDERR.puts "WARNING: Invalid country code #{country_code.upcase}"
53
- country = country_code
54
- end
41
+ country = @record.delete(:nationality)
42
+ agent = @record.delete(:agent)
55
43
 
56
- @record[:country] = country
44
+ @record[:vessel] = PLA::Vessel.new(name, country, agent).to_h
57
45
  end
58
46
 
59
47
  def normalise_fields!
@@ -0,0 +1,32 @@
1
+ require 'iso_country_codes'
2
+
3
+ class PLA
4
+ class Vessel
5
+ def initialize name, country, agent
6
+ @name = name
7
+ @country = normalise_country(country)
8
+ @agent = agent
9
+ end
10
+
11
+ def to_h
12
+ {
13
+ name: @name,
14
+ country: @country,
15
+ agent: @agent,
16
+ google: "https://www.google.co.uk/search?q=site:vesselfinder.com #{@name}"
17
+ }
18
+ end
19
+
20
+ def normalise_country country_code
21
+ begin
22
+ country = IsoCountryCodes.find(country_code).name
23
+ rescue IsoCountryCodes::UnknownCodeError
24
+ STDERR.puts "WARNING: Invalid country code #{country_code.upcase}"
25
+ country = country_code
26
+ end
27
+
28
+ country
29
+ end
30
+
31
+ end
32
+ end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "pla"
7
- spec.version = '0.2.0'
7
+ spec.version = '0.3.0'
8
8
  spec.authors = ["jspc"]
9
9
  spec.email = ["james@zero-internet.org.uk"]
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jspc
@@ -101,7 +101,7 @@ files:
101
101
  - lib/pla/departures.rb
102
102
  - lib/pla/movement.rb
103
103
  - lib/pla/movements.rb
104
- - lib/pla/ship.rb
104
+ - lib/pla/vessel.rb
105
105
  - pla.gemspec
106
106
  homepage: https://github.com/jspc/pla
107
107
  licenses:
@@ -1,14 +0,0 @@
1
- class PLA
2
- class Ship
3
- def initialize ship
4
- @name = ship
5
- end
6
-
7
- def to_h
8
- {
9
- name: @name,
10
- google: "https://www.google.co.uk/search?q=site:vesselfinder.com #{@name}"
11
- }
12
- end
13
- end
14
- end