japan_etc 0.5.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'japan_etc/database_provider/base'
4
+ require 'japan_etc/tollbooth'
5
+ require 'faraday'
6
+ require 'nokogiri'
7
+
8
+ module JapanETC
9
+ module DatabaseProvider
10
+ # http://www.nagoya-expressway.or.jp/etc/etc-lane.html
11
+ class PastDatabase < Base
12
+ def source_id
13
+ 'PastDatabase'
14
+ end
15
+
16
+ def fetch_tollbooths
17
+ rows.map do |row|
18
+ create_tollbooth_from_row(row)
19
+ end
20
+ end
21
+
22
+ def create_tollbooth_from_row(row)
23
+ identifier = Tollbooth::Identifier.from(row[0])
24
+
25
+ road = Road.new(row[1], row[2])
26
+
27
+ Tollbooth.new(
28
+ identifier: identifier,
29
+ road: road,
30
+ name: row[3],
31
+ direction: row[4],
32
+ entrance_or_exit: row[5],
33
+ note: row[6],
34
+ source: source_id,
35
+ priority: -1
36
+ )
37
+ end
38
+
39
+ def rows
40
+ CSV.parse(csv, headers: :first_row)
41
+ end
42
+
43
+ def csv
44
+ path = File.join(__dir__, 'past_database.csv')
45
+ File.read(path)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -23,7 +23,7 @@ module JapanETC
23
23
  def initialize(name, route_name = nil)
24
24
  raise ValidationError, '#name cannot be nil' if name.nil?
25
25
 
26
- super(normalize(name), normalize(route_name))
26
+ super(remove_whitespaces(normalize(name)), remove_whitespaces(normalize(route_name)))
27
27
  end
28
28
 
29
29
  def abbreviation
@@ -11,7 +11,8 @@ module JapanETC
11
11
  include Comparable
12
12
  include Util
13
13
 
14
- attr_accessor :identifier, :road, :name, :entrance_or_exit, :direction, :notes
14
+ attr_accessor :identifier, :road, :name, :entrance_or_exit, :direction, :notes,
15
+ :source, :priority
15
16
 
16
17
  def self.create(
17
18
  road_number:,
@@ -21,23 +22,46 @@ module JapanETC
21
22
  name:,
22
23
  direction: nil,
23
24
  entrance_or_exit: nil,
24
- note: nil
25
+ note: nil,
26
+ source: nil,
27
+ priority: 0
25
28
  )
26
29
  identifier = Identifier.new(road_number, tollbooth_number)
27
30
  road = Road.new(road_name, route_name)
28
- new(identifier, road, name, direction, entrance_or_exit, note)
31
+
32
+ new(
33
+ identifier: identifier,
34
+ road: road,
35
+ name: name,
36
+ direction: direction,
37
+ entrance_or_exit: entrance_or_exit,
38
+ note: note,
39
+ source: source,
40
+ priority: priority
41
+ )
29
42
  end
30
43
 
31
- def initialize(identifier, road, name, direction = nil, entrance_or_exit = nil, note = nil) # rubocop:disable Metrics/LineLength
44
+ def initialize(
45
+ identifier:,
46
+ road:,
47
+ name:,
48
+ direction:,
49
+ entrance_or_exit:,
50
+ note:,
51
+ source:,
52
+ priority:
53
+ )
32
54
  raise ValidationError if identifier.nil? || road.nil? || name.nil?
33
55
 
34
56
  @identifier = identifier
35
57
  @road = road
36
- @name = normalize(name)
58
+ @name = remove_whitespaces(normalize(name))
37
59
  @direction = direction
38
60
  @entrance_or_exit = entrance_or_exit
39
61
  @notes = []
40
62
  notes << normalize(note) if note
63
+ @source = source
64
+ @priority = priority
41
65
 
42
66
  normalize!
43
67
  end
@@ -61,10 +85,13 @@ module JapanETC
61
85
  result = identifier <=> other.identifier
62
86
  return result unless result.zero?
63
87
 
88
+ result = priority <=> other.priority
89
+ return -result unless result.zero? # Tollbooth with higher priority comes first
90
+
64
91
  return -1 if !obsolete? && other.obsolete?
65
92
  return 1 if obsolete? && !other.obsolete?
66
93
 
67
- [:road, :name].each do |attribute|
94
+ %i[road name source].each do |attribute|
68
95
  result = send(attribute) <=> other.send(attribute)
69
96
  return result unless result.zero?
70
97
  end
@@ -79,7 +106,8 @@ module JapanETC
79
106
  name,
80
107
  direction,
81
108
  entrance_or_exit,
82
- notes.empty? ? nil : notes.join(' ')
109
+ notes.empty? ? nil : notes.join(' '),
110
+ source
83
111
  ].flatten
84
112
  end
85
113
 
@@ -205,6 +233,10 @@ module JapanETC
205
233
  include Comparable
206
234
  include Util
207
235
 
236
+ def self.from(string)
237
+ new(*string.split('-'))
238
+ end
239
+
208
240
  def initialize(road_number, tollbooth_number)
209
241
  road_number = convert_to_integer(road_number)
210
242
  raise ValidationError, '#road_number cannot be nil' if road_number.nil?
@@ -7,7 +7,7 @@ module JapanETC
7
7
  def normalize(string)
8
8
  return nil unless string
9
9
 
10
- convert_fullwidth_characters_to_halfwidth(string).strip
10
+ convert_fullwidth_characters_to_halfwidth(string)
11
11
  end
12
12
 
13
13
  def convert_fullwidth_characters_to_halfwidth(string)
@@ -16,6 +16,12 @@ module JapanETC
16
16
  string.tr(' A-Za-z0-9', ' A-Za-z0-9')
17
17
  end
18
18
 
19
+ def remove_whitespaces(string)
20
+ return nil unless string
21
+
22
+ string.tr(' ', '')
23
+ end
24
+
19
25
  def convert_to_integer(object)
20
26
  case object
21
27
  when Numeric
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JapanETC
4
- VERSION = '0.5.2'
4
+ VERSION = '0.10.0'
5
5
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: japan_etc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0.15'
33
+ version: '1.0'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0.15'
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: nokogiri
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -102,12 +116,16 @@ files:
102
116
  - japan_etc.gemspec
103
117
  - lib/japan_etc.rb
104
118
  - lib/japan_etc/database.rb
105
- - lib/japan_etc/database_provider.rb
106
119
  - lib/japan_etc/database_provider/base.rb
120
+ - lib/japan_etc/database_provider/base_nexco.rb
107
121
  - lib/japan_etc/database_provider/hanshin_expressway.rb
108
122
  - lib/japan_etc/database_provider/metropolitan_expressway.rb
109
123
  - lib/japan_etc/database_provider/nagoya_expressway.rb
110
- - lib/japan_etc/database_provider/nexco.rb
124
+ - lib/japan_etc/database_provider/nexco_central.rb
125
+ - lib/japan_etc/database_provider/nexco_east.rb
126
+ - lib/japan_etc/database_provider/nexco_west.rb
127
+ - lib/japan_etc/database_provider/past_database.csv
128
+ - lib/japan_etc/database_provider/past_database.rb
111
129
  - lib/japan_etc/direction.rb
112
130
  - lib/japan_etc/entrance_or_exit.rb
113
131
  - lib/japan_etc/error.rb
@@ -134,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
152
  - !ruby/object:Gem::Version
135
153
  version: '0'
136
154
  requirements: []
137
- rubygems_version: 3.0.3
155
+ rubygems_version: 3.1.2
138
156
  signing_key:
139
157
  specification_version: 4
140
158
  summary: Japan ETC (Electronic Toll Collection System) database
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'japan_etc/database_provider/metropolitan_expressway'
4
- require 'japan_etc/database_provider/hanshin_expressway'
5
- require 'japan_etc/database_provider/nagoya_expressway'
6
- require 'japan_etc/database_provider/nexco'