konbikol 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17cccb076cc787892f8df8c875b185157f1b8a31e6c0987f824a61c2f1fd2697
4
- data.tar.gz: 7b6158a9a144621adbd1366ee9d66f2355610493b4ac32e3d4a9db1df30d6857
3
+ metadata.gz: ec1d54398a152292c0b3daaa531a62d12c0cad311f553679785665dd5232ff14
4
+ data.tar.gz: 22c8b221a5549699b70966139a5bbbb7b8ad1cd39f88fdfef0af508ca41f9177
5
5
  SHA512:
6
- metadata.gz: 96cd820e81c2935cbfa98765398ae05a92b7b8db75344c390908fb364ed1574651fd23c881e79e6a614d12808494bd77e5003c7819a884d65b852df51859da48
7
- data.tar.gz: 26a41d9cb65744e6fd67b7fd00f0dffebf5c9d4400cb5ed6b13314a8ceea92f64fd670a0aa81207fbc99b08606b66e8bad03728f171664a94728b9d2d8805e7f
6
+ metadata.gz: 34a5711d63ea9c68e32f8da1df639e2d3c0cc04a8ed2588d92e73ec51660983c33b9d20ebb6a30656e07be2085573c3d807b9070c289f3a413bb32f8f9fd08cb
7
+ data.tar.gz: c434bf9cf20c843e31e5fc2617e91aaa3e62587e38b3d73e0e1ad078a25753ececd9ff8aff65dc0e4a11c86e353bf1bfa19771385f2aad5e6f70ba816247c3f6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- konbikol (0.1.4)
4
+ konbikol (0.1.5)
5
5
  icalendar (~> 2.5.1)
6
6
  pdf-reader (~> 2.1.0)
7
7
  tzinfo (~> 1.2.5)
@@ -126,11 +126,25 @@ module Konbikol
126
126
 
127
127
  attr_reader :ticket_text
128
128
 
129
+ STATION_AND_REST_REGEX = /^(?<station>\D+(\b|\.))\s+(?<rest>\d.+)$/
130
+
129
131
  def departure
130
132
  return @departure if @departure
131
- line = ticket_text.lines[departure_line_index].split(/\s{2,}/)
132
133
 
133
- raw_train = line[3]
134
+ departure_line = ticket_text.lines[departure_line_index]
135
+
136
+ match_result = departure_line.match(STATION_AND_REST_REGEX)
137
+ unless match_result
138
+ raise "Departure line didn't match the regex to detect the station and the rest of columns, " \
139
+ "here's how the line looks like:\n\n#{departure_line}"
140
+ end
141
+
142
+ station = match_result[:station]
143
+ rest = match_result[:rest]
144
+
145
+ rest_columns = rest.split(/\s{2,}/)
146
+
147
+ raw_train = rest_columns[2]
134
148
  train = raw_train.split(' ').first(2).join(' ')
135
149
 
136
150
  # If everything's fine, the departure line should look somewhat like this:
@@ -146,12 +160,12 @@ module Konbikol
146
160
  # This causes troubles for us because we assume that there are at least two spaces between
147
161
  # columns, so we have to accommodate for that.
148
162
  is_there_just_one_space_between_train_and_distance = raw_train.split(' ').size != 2
149
- seat = is_there_just_one_space_between_train_and_distance ? line[4] : line[5]
163
+ seat = is_there_just_one_space_between_train_and_distance ? rest_columns[3] : rest_columns[4]
150
164
 
151
165
  @departure = {
152
- station: line[0],
153
- date: line[1],
154
- time: line[2],
166
+ station: station,
167
+ date: rest_columns[0],
168
+ time: rest_columns[1],
155
169
  train: train,
156
170
  seat: seat,
157
171
  }
@@ -160,13 +174,23 @@ module Konbikol
160
174
  def arrival
161
175
  return @arrival if @arrival
162
176
 
163
- line = ticket_text.lines[departure_line_index + 1].split(/\s{2,}/)
177
+ arrival_line = ticket_text.lines[departure_line_index + 1]
178
+ match_result = arrival_line.match(STATION_AND_REST_REGEX)
179
+ unless match_result
180
+ raise "Arrival line didn't match the regex to detect the station and the rest of columns, " \
181
+ "here's how the line looks like:\n\n#{arrival_line}"
182
+ end
183
+
184
+ station = match_result[:station]
185
+ rest = match_result[:rest]
186
+
187
+ rest_columns = rest.split(/\s{2,}/)
164
188
 
165
189
  @arrival = {
166
- station: line[0],
167
- date: line[1],
168
- time: line[2],
169
- carriage: line[3],
190
+ station: station,
191
+ date: rest_columns[0],
192
+ time: rest_columns[1],
193
+ carriage: rest_columns[2],
170
194
  }
171
195
  end
172
196
 
@@ -1,3 +1,3 @@
1
1
  module Konbikol
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konbikol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Cieślak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-27 00:00:00.000000000 Z
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler