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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/konbikol/ticket.rb +35 -11
- data/lib/konbikol/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec1d54398a152292c0b3daaa531a62d12c0cad311f553679785665dd5232ff14
|
4
|
+
data.tar.gz: 22c8b221a5549699b70966139a5bbbb7b8ad1cd39f88fdfef0af508ca41f9177
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34a5711d63ea9c68e32f8da1df639e2d3c0cc04a8ed2588d92e73ec51660983c33b9d20ebb6a30656e07be2085573c3d807b9070c289f3a413bb32f8f9fd08cb
|
7
|
+
data.tar.gz: c434bf9cf20c843e31e5fc2617e91aaa3e62587e38b3d73e0e1ad078a25753ececd9ff8aff65dc0e4a11c86e353bf1bfa19771385f2aad5e6f70ba816247c3f6
|
data/Gemfile.lock
CHANGED
data/lib/konbikol/ticket.rb
CHANGED
@@ -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
|
-
|
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 ?
|
163
|
+
seat = is_there_just_one_space_between_train_and_distance ? rest_columns[3] : rest_columns[4]
|
150
164
|
|
151
165
|
@departure = {
|
152
|
-
station:
|
153
|
-
date:
|
154
|
-
time:
|
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
|
-
|
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:
|
167
|
-
date:
|
168
|
-
time:
|
169
|
-
carriage:
|
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
|
|
data/lib/konbikol/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2019-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|