konbikol 0.1.0 → 0.1.1

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: 5c658cf6ef28ae8fa193f5f359d1188c7a11d76c0864718a8c5be253b421c735
4
- data.tar.gz: 3b3e7c35531d58135d1d30aa29271eec67ceea5d25e192f41b149f18419af0b1
3
+ metadata.gz: 8a97ce970519977318814eb7f2534781025a41959d3c3d40fda185a1117344b5
4
+ data.tar.gz: 81a9d5f0b0da7ad398038a44b005b84e100a56c8ace60050c28925689f78906f
5
5
  SHA512:
6
- metadata.gz: 7f1ac3b8d995ca822bec680bafb03eac5c24d8196667d224b4cc916da802af0902f12e532c58cf6959cbfb8fc2d9e5a6bfbed45df18d9c1fa2c206daa5db4c68
7
- data.tar.gz: df2f1a8dfc9e3518ccb5c9a3bfa62f8de1bbfe1b290569a0b16b7c0e4609e3e5f14bd8b7f41834fff5f3e948520322909808a1019848fa3baf12b139cfb58e98
6
+ metadata.gz: 5f79b29563d9b82c8038f21cf8105e242bb9a9bc7885834a1f228a50dc16814f9c8b6879e95a8fd706f868b3d2af3e8bc613d5cfb34bccf07cba13ae484d8a20
7
+ data.tar.gz: cdcee30ed86946f2f7bb04bde087587f0f3aa6854e70a1d5fecd004611ecb7c42b7b9477c576ae94e1f23b2856e5a509e7192e2a6a29fcc037cd65d94419db77
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- konbikol (0.1.0)
4
+ konbikol (0.1.1)
5
5
  icalendar (~> 2.5.1)
6
6
  pdf-reader (~> 2.1.0)
7
7
  tzinfo (~> 1.2.5)
@@ -41,4 +41,4 @@ DEPENDENCIES
41
41
  rake (~> 10.0)
42
42
 
43
43
  BUNDLED WITH
44
- 1.16.6
44
+ 1.17.1
data/README.md CHANGED
@@ -1,39 +1,42 @@
1
1
  # Konbikol
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/konbikol`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Converts PKP Intercity PDF train tickets to iCalendar events.
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'konbikol'
7
+ ```
8
+ gem install konbikol
13
9
  ```
14
10
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
11
+ ## Usage
20
12
 
21
- $ gem install konbikol
13
+ ```
14
+ konbikol file.pdf
15
+ ```
22
16
 
23
- ## Usage
17
+ This will try to open file.pdf, convert it to a ticket, then save it to a temporary directory and
18
+ then attempt to open that file (given that there's `open` command in your path).
24
19
 
25
- TODO: Write usage instructions here
20
+ By default on macOS, this will result in Calendar asking you about what calendar you want to add the
21
+ event to. Well, at least that's what happens for me since I have more than one calendar.
26
22
 
27
23
  ## Development
28
24
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+ After checking out the repo, run `bundle` to install dependencies. Then, run `rake test` to run the
26
+ tests.
30
27
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new
29
+ version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
30
+ will create a git tag for the version, push git commits and tags, and push the `.gem` file to
31
+ [rubygems.org](https://rubygems.org).
32
32
 
33
33
  ## Contributing
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/ravicious/konbikol. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ravicious/konbikol. This
36
+ project is intended to be a safe, welcoming space for collaboration, and contributors are expected
37
+ to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
38
 
37
39
  ## Code of Conduct
38
40
 
39
- Everyone interacting in the Konbikol project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ravicious/konbikol/blob/master/CODE_OF_CONDUCT.md).
41
+ Everyone interacting in the Konbikol project’s codebases, issue trackers, chat rooms and mailing
42
+ lists is expected to follow the [code of conduct](https://github.com/ravicious/konbikol/blob/master/CODE_OF_CONDUCT.md).
@@ -50,12 +50,12 @@ module Konbikol
50
50
  end
51
51
 
52
52
  def departure_time
53
- departure_line[2]
53
+ departure.fetch(:time)
54
54
  end
55
55
 
56
56
  # The format is `dd.mm` E.g. `23.04`.
57
57
  def departure_date
58
- departure_line[1]
58
+ departure.fetch(:date)
59
59
  end
60
60
 
61
61
  def departure_datetime
@@ -72,15 +72,15 @@ module Konbikol
72
72
  end
73
73
 
74
74
  def departure_station
75
- departure_line[0]
75
+ departure.fetch(:station)
76
76
  end
77
77
 
78
78
  def arrival_time
79
- arrival_line[2]
79
+ arrival.fetch(:time)
80
80
  end
81
81
 
82
82
  def arrival_date
83
- arrival_line[1]
83
+ arrival.fetch(:date)
84
84
  end
85
85
 
86
86
  def arrival_datetime
@@ -97,19 +97,19 @@ module Konbikol
97
97
  end
98
98
 
99
99
  def arrival_station
100
- arrival_line[0]
100
+ arrival.fetch(:station)
101
101
  end
102
102
 
103
103
  def carriage
104
- arrival_line[3]
104
+ arrival.fetch(:carriage)
105
105
  end
106
106
 
107
107
  def seat
108
- departure_line[5]
108
+ departure.fetch(:seat)
109
109
  end
110
110
 
111
111
  def train
112
- departure_line[3]
112
+ departure.fetch(:train)
113
113
  end
114
114
 
115
115
  def purchase_time
@@ -122,12 +122,48 @@ module Konbikol
122
122
 
123
123
  attr_reader :ticket_text
124
124
 
125
- def departure_line
126
- @departure_line ||= ticket_text.lines[departure_line_index].split(/\s{2,}/)
127
- end
128
-
129
- def arrival_line
130
- @arrival_line ||= ticket_text.lines[departure_line_index + 1].split(/\s{2,}/)
125
+ def departure
126
+ return @departure if @departure
127
+ line = ticket_text.lines[departure_line_index].split(/\s{2,}/)
128
+
129
+ raw_train = line[3]
130
+ train = raw_train.split(' ').first(2).join(' ')
131
+
132
+ # If everything's fine, the departure line should look somewhat like this:
133
+ #
134
+ # Foo 22.12 13:08 TLK 1111 123 25 o 48,00 zł
135
+ #
136
+ # But sometimes the train ID is too long and there's just one space between the train column
137
+ # and the distance column:
138
+ #
139
+ # Foo 22.12 13:08 TLK 11111 123 25 o 48,00 zł
140
+ # ^ here
141
+ #
142
+ # This causes troubles for us because we assume that there are at least two spaces between
143
+ # columns, so we have to accommodate for that.
144
+ is_there_just_one_space_between_train_and_distance = raw_train.split(' ').size != 2
145
+ seat = is_there_just_one_space_between_train_and_distance ? line[4] : line[5]
146
+
147
+ @departure = {
148
+ station: line[0],
149
+ date: line[1],
150
+ time: line[2],
151
+ train: train,
152
+ seat: seat,
153
+ }
154
+ end
155
+
156
+ def arrival
157
+ return @arrival if @arrival
158
+
159
+ line = ticket_text.lines[departure_line_index + 1].split(/\s{2,}/)
160
+
161
+ @arrival = {
162
+ station: line[0],
163
+ date: line[1],
164
+ time: line[2],
165
+ carriage: line[3],
166
+ }
131
167
  end
132
168
 
133
169
  def departure_line_index
@@ -1,3 +1,3 @@
1
1
  module Konbikol
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.0
4
+ version: 0.1.1
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: 2018-11-25 00:00:00.000000000 Z
11
+ date: 2018-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler