fuel_surcharge 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +57 -0
- data/.github_changelog_generator +1 -0
- data/.rubocop.yml +2 -2
- data/.standard.yml +4 -0
- data/CHANGELOG.md +23 -8
- data/Gemfile.lock +17 -17
- data/README.md +1 -1
- data/Rakefile +1 -12
- data/exe/fuel_surcharge +3 -3
- data/fuel_surcharge.gemspec +3 -5
- data/lib/fuel_surcharge/chronopost.rb +32 -38
- data/lib/fuel_surcharge/html_scanner.rb +35 -0
- data/lib/fuel_surcharge/string_formatter.rb +13 -0
- data/lib/fuel_surcharge/tnt.rb +41 -13
- data/lib/fuel_surcharge/version.rb +1 -1
- data/sideci.yml +10 -0
- metadata +12 -22
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69aed266b7e88f7c91f9e89208cc7ec34d837acf6674f602c19a466ce9b2b995
|
4
|
+
data.tar.gz: 1053ad24d7dab572cba924c78ddfbbf678d27b8174fbc57fb3830a0bfa0a09a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec61592c3cf6e60cd2bde7db257012f266d7f02e5e7690d964e255c22edc0e610e79ee8724c4806f93e65d39791517acd78cb033abc49d483c914172a0296df8
|
7
|
+
data.tar.gz: c72c8e1380fc086d439bb965a31fc9286cb62eebd39c4cf817fe386d91e445d5fb90585cb9f2207726953f33743ac3b6047e76a1dc2c67ef68959041532ade78
|
@@ -0,0 +1,57 @@
|
|
1
|
+
version: 2
|
2
|
+
references:
|
3
|
+
unit: &unit
|
4
|
+
run:
|
5
|
+
name: Run test suite
|
6
|
+
command: bundle exec rake
|
7
|
+
restore: &restore
|
8
|
+
restore_cache:
|
9
|
+
keys:
|
10
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
11
|
+
# fallback to using the latest cache if no exact match is found
|
12
|
+
- v1-dependencies-
|
13
|
+
bundle: &bundle
|
14
|
+
run:
|
15
|
+
name: install dependencies
|
16
|
+
command: gem install bundler && bundle install --path vendor/bundle
|
17
|
+
save: &save
|
18
|
+
save_cache:
|
19
|
+
paths:
|
20
|
+
- ./vendor/bundle
|
21
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
22
|
+
jobs:
|
23
|
+
"ruby-2.5":
|
24
|
+
docker:
|
25
|
+
- image: circleci/ruby:2.5
|
26
|
+
steps:
|
27
|
+
- checkout
|
28
|
+
- <<: *restore
|
29
|
+
- <<: *bundle
|
30
|
+
- <<: *save
|
31
|
+
- <<: *unit
|
32
|
+
"ruby-2.6":
|
33
|
+
docker:
|
34
|
+
- image: circleci/ruby:2.6
|
35
|
+
steps:
|
36
|
+
- checkout
|
37
|
+
- <<: *restore
|
38
|
+
- <<: *bundle
|
39
|
+
- <<: *save
|
40
|
+
- <<: *unit
|
41
|
+
"jruby":
|
42
|
+
docker:
|
43
|
+
- image: circleci/jruby:latest
|
44
|
+
steps:
|
45
|
+
- checkout
|
46
|
+
- <<: *restore
|
47
|
+
- <<: *bundle
|
48
|
+
- <<: *save
|
49
|
+
- <<: *unit
|
50
|
+
|
51
|
+
workflows:
|
52
|
+
version: 2
|
53
|
+
build:
|
54
|
+
jobs:
|
55
|
+
- "ruby-2.5"
|
56
|
+
- "ruby-2.6"
|
57
|
+
- "jruby"
|
@@ -0,0 +1 @@
|
|
1
|
+
future-release=1.2.0
|
data/.rubocop.yml
CHANGED
data/.standard.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [1.2.0](https://github.com/levups/fuel_surcharge/tree/1.2.0) (2019-04-23)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/levups/fuel_surcharge/compare/v1.1.0...1.2.0)
|
6
|
+
|
7
|
+
**Fixed bugs:**
|
8
|
+
|
9
|
+
- Error in gem push workflow action [\#32](https://github.com/levups/fuel_surcharge/issues/32)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Correct github workflow for gem push [\#33](https://github.com/levups/fuel_surcharge/pull/33) ([bobmaerten](https://github.com/bobmaerten))
|
14
|
+
- Fix versions for rubocop and standard gem in Sider [\#44](https://github.com/levups/fuel_surcharge/pull/44) ([bobmaerten](https://github.com/bobmaerten))
|
15
|
+
- Move out of Travis CI into Circle CI [\#47](https://github.com/levups/fuel_surcharge/pull/47) ([czj](https://github.com/czj))
|
16
|
+
- Optimize chronopost scrapping [\#42](https://github.com/levups/fuel_surcharge/pull/42) ([bobmaerten](https://github.com/bobmaerten))
|
17
|
+
- Replace Rubocop with standard.rb [\#41](https://github.com/levups/fuel_surcharge/pull/41) ([bobmaerten](https://github.com/bobmaerten))
|
18
|
+
- Rewrite TNT class to stabilize it at any time of the month [\#48](https://github.com/levups/fuel_surcharge/pull/48) ([czj](https://github.com/czj))
|
19
|
+
|
3
20
|
## [v1.1.0](https://github.com/levups/fuel_surcharge/tree/v1.1.0) (2019-02-08)
|
21
|
+
|
4
22
|
[Full Changelog](https://github.com/levups/fuel_surcharge/compare/v1.0.0...v1.1.0)
|
5
23
|
|
6
24
|
**Implemented enhancements:**
|
@@ -13,17 +31,14 @@
|
|
13
31
|
|
14
32
|
**Merged pull requests:**
|
15
33
|
|
34
|
+
- Release v1.1.0 [\#31](https://github.com/levups/fuel_surcharge/pull/31) ([bobmaerten](https://github.com/bobmaerten))
|
16
35
|
- Remove gem signature on publish [\#30](https://github.com/levups/fuel_surcharge/pull/30) ([bobmaerten](https://github.com/bobmaerten))
|
17
36
|
- Check workflow agains git ref before running other actions [\#29](https://github.com/levups/fuel_surcharge/pull/29) ([bobmaerten](https://github.com/bobmaerten))
|
18
37
|
- Github action auto publish [\#28](https://github.com/levups/fuel_surcharge/pull/28) ([bobmaerten](https://github.com/bobmaerten))
|
19
38
|
- Fix chronopost time period extract [\#27](https://github.com/levups/fuel_surcharge/pull/27) ([bobmaerten](https://github.com/bobmaerten))
|
20
|
-
- Bump rubocop from 0.63.0 to 0.63.1 [\#24](https://github.com/levups/fuel_surcharge/pull/24) ([dependabot[bot]](https://github.com/apps/dependabot))
|
21
|
-
- Bump http from 4.0.2 to 4.0.3 [\#23](https://github.com/levups/fuel_surcharge/pull/23) ([dependabot[bot]](https://github.com/apps/dependabot))
|
22
|
-
- Bump rubocop from 0.62.0 to 0.63.0 [\#22](https://github.com/levups/fuel_surcharge/pull/22) ([dependabot[bot]](https://github.com/apps/dependabot))
|
23
|
-
- Bump http from 4.0.1 to 4.0.2 [\#21](https://github.com/levups/fuel_surcharge/pull/21) ([dependabot[bot]](https://github.com/apps/dependabot))
|
24
|
-
- Bump http from 4.0.0 to 4.0.1 [\#20](https://github.com/levups/fuel_surcharge/pull/20) ([dependabot[bot]](https://github.com/apps/dependabot))
|
25
39
|
|
26
40
|
## [v1.0.0](https://github.com/levups/fuel_surcharge/tree/v1.0.0) (2019-01-04)
|
41
|
+
|
27
42
|
[Full Changelog](https://github.com/levups/fuel_surcharge/compare/v0.2.0...v1.0.0)
|
28
43
|
|
29
44
|
**Merged pull requests:**
|
@@ -34,12 +49,11 @@
|
|
34
49
|
- Bump to v1.0.0 [\#16](https://github.com/levups/fuel_surcharge/pull/16) ([czj](https://github.com/czj))
|
35
50
|
- Include and comply to relaxed Rubocop style [\#15](https://github.com/levups/fuel_surcharge/pull/15) ([czj](https://github.com/czj))
|
36
51
|
- Add BigDecimal compatibility for ruby 2.6 [\#13](https://github.com/levups/fuel_surcharge/pull/13) ([bobmaerten](https://github.com/bobmaerten))
|
37
|
-
- Bump rake from 12.3.1 to 12.3.2 [\#12](https://github.com/levups/fuel_surcharge/pull/12) ([dependabot[bot]](https://github.com/apps/dependabot))
|
38
|
-
- Update rake requirement from ~\> 10.0 to ~\> 12.3 [\#11](https://github.com/levups/fuel_surcharge/pull/11) ([dependabot[bot]](https://github.com/apps/dependabot))
|
39
52
|
- Fix and unify time period tests [\#9](https://github.com/levups/fuel_surcharge/pull/9) ([bobmaerten](https://github.com/bobmaerten))
|
40
53
|
- Fix fuel surcharge binary [\#8](https://github.com/levups/fuel_surcharge/pull/8) ([bobmaerten](https://github.com/bobmaerten))
|
41
54
|
|
42
55
|
## [v0.2.0](https://github.com/levups/fuel_surcharge/tree/v0.2.0) (2018-11-28)
|
56
|
+
|
43
57
|
[Full Changelog](https://github.com/levups/fuel_surcharge/compare/v0.1.0...v0.2.0)
|
44
58
|
|
45
59
|
**Implemented enhancements:**
|
@@ -57,10 +71,11 @@
|
|
57
71
|
- Upgrade Travis CI dist to Xenial [\#2](https://github.com/levups/fuel_surcharge/pull/2) ([czj](https://github.com/czj))
|
58
72
|
|
59
73
|
## [v0.1.0](https://github.com/levups/fuel_surcharge/tree/v0.1.0) (2018-11-25)
|
74
|
+
|
60
75
|
**Merged pull requests:**
|
61
76
|
|
62
77
|
- Prepare for initial release [\#1](https://github.com/levups/fuel_surcharge/pull/1) ([bobmaerten](https://github.com/bobmaerten))
|
63
78
|
|
64
79
|
|
65
80
|
|
66
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
81
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fuel_surcharge (1.
|
4
|
+
fuel_surcharge (1.2.0)
|
5
5
|
http (~> 4.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (5.2.
|
10
|
+
activesupport (5.2.3)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 0.7, < 2)
|
13
13
|
minitest (~> 5.1)
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
addressable (2.5.2)
|
16
16
|
public_suffix (>= 2.0.2, < 4.0)
|
17
17
|
ast (2.4.0)
|
18
|
-
concurrent-ruby (1.1.
|
18
|
+
concurrent-ruby (1.1.5)
|
19
19
|
domain_name (0.5.20180417)
|
20
20
|
unf (>= 0.0.5, < 1.0.0)
|
21
21
|
faraday (0.15.4)
|
@@ -30,7 +30,7 @@ GEM
|
|
30
30
|
rainbow (>= 2.1)
|
31
31
|
rake (>= 10.0)
|
32
32
|
retriable (~> 2.1)
|
33
|
-
http (4.
|
33
|
+
http (4.1.1)
|
34
34
|
addressable (~> 2.3)
|
35
35
|
http-cookie (~> 1.0)
|
36
36
|
http-form_data (~> 2.0)
|
@@ -39,43 +39,44 @@ GEM
|
|
39
39
|
domain_name (~> 0.5)
|
40
40
|
http-form_data (2.1.1)
|
41
41
|
http_parser.rb (0.6.0)
|
42
|
-
i18n (1.
|
42
|
+
i18n (1.6.0)
|
43
43
|
concurrent-ruby (~> 1.0)
|
44
44
|
jaro_winkler (1.5.2)
|
45
45
|
minitest (5.11.3)
|
46
46
|
minitest-stub_any_instance (1.0.2)
|
47
47
|
multi_json (1.13.1)
|
48
48
|
multipart-post (2.0.0)
|
49
|
-
octokit (4.
|
49
|
+
octokit (4.14.0)
|
50
50
|
sawyer (~> 0.8.0, >= 0.5.3)
|
51
|
-
parallel (1.
|
52
|
-
parser (2.6.
|
51
|
+
parallel (1.17.0)
|
52
|
+
parser (2.6.2.1)
|
53
53
|
ast (~> 2.4.0)
|
54
|
-
|
54
|
+
psych (3.1.0)
|
55
55
|
public_suffix (3.0.3)
|
56
56
|
rainbow (3.0.0)
|
57
57
|
rake (12.3.2)
|
58
|
-
relaxed-rubocop (2.3.1)
|
59
58
|
retriable (2.1.0)
|
60
|
-
rubocop (0.
|
59
|
+
rubocop (0.67.2)
|
61
60
|
jaro_winkler (~> 1.5.1)
|
62
61
|
parallel (~> 1.10)
|
63
62
|
parser (>= 2.5, != 2.5.1.1)
|
64
|
-
|
63
|
+
psych (>= 3.1.0)
|
65
64
|
rainbow (>= 2.2.2, < 4.0)
|
66
65
|
ruby-progressbar (~> 1.7)
|
67
|
-
unicode-display_width (
|
66
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
68
67
|
ruby-progressbar (1.10.0)
|
69
68
|
sawyer (0.8.1)
|
70
69
|
addressable (>= 2.3.5, < 2.6)
|
71
70
|
faraday (~> 0.8, < 1.0)
|
71
|
+
standard (0.0.39)
|
72
|
+
rubocop (~> 0.67.1)
|
72
73
|
thread_safe (0.3.6)
|
73
74
|
tzinfo (1.2.5)
|
74
75
|
thread_safe (~> 0.1)
|
75
76
|
unf (0.1.4)
|
76
77
|
unf_ext
|
77
|
-
unf_ext (0.0.7.
|
78
|
-
unicode-display_width (1.
|
78
|
+
unf_ext (0.0.7.6)
|
79
|
+
unicode-display_width (1.5.0)
|
79
80
|
|
80
81
|
PLATFORMS
|
81
82
|
ruby
|
@@ -87,8 +88,7 @@ DEPENDENCIES
|
|
87
88
|
minitest (~> 5.0)
|
88
89
|
minitest-stub_any_instance (~> 1.0)
|
89
90
|
rake (~> 12.3)
|
90
|
-
|
91
|
-
rubocop (~> 0.62)
|
91
|
+
standard (~> 0.0.39)
|
92
92
|
|
93
93
|
BUNDLED WITH
|
94
94
|
2.0.1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# A transporters fuel surcharge fetcher
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![CircleCI](https://circleci.com/gh/levups/fuel_surcharge/tree/master.svg?style=svg)](https://circleci.com/gh/levups/fuel_surcharge/tree/master)
|
4
4
|
|
5
5
|
Retrieve current air and road rates applied to transporters shipping costs and
|
6
6
|
convert them to multipliers you can directly use in your app to calculate
|
data/Rakefile
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "github_changelog_generator/task"
|
5
|
-
require "rake/testtask"
|
6
5
|
require "http"
|
7
6
|
require "json"
|
7
|
+
require "rake/testtask"
|
8
8
|
|
9
9
|
Rake::TestTask.new(:test) do |t|
|
10
10
|
t.libs << "test"
|
@@ -30,15 +30,4 @@ task :should_we_release_a_new_version do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
34
|
-
latest_release = `git tag --sort=taggerdate | tail -n 1`.strip
|
35
|
-
next_release = "v#{FuelSurcharge::VERSION}"
|
36
|
-
|
37
|
-
config.user = "levups"
|
38
|
-
config.project = "fuel_surcharge"
|
39
|
-
config.future_release = next_release if next_release > latest_release
|
40
|
-
config.add_issues_wo_labels = false
|
41
|
-
config.exclude_labels = "release"
|
42
|
-
end
|
43
|
-
|
44
33
|
task default: :test
|
data/exe/fuel_surcharge
CHANGED
@@ -9,10 +9,10 @@ tnt = FuelSurcharge::TNT.new
|
|
9
9
|
|
10
10
|
[colissimo, chronopost, tnt].each do |fuel_surcharge|
|
11
11
|
puts "---------------------------------------------------"
|
12
|
-
puts "# Fuel surcharges for #{fuel_surcharge.class.name.split(
|
12
|
+
puts "# Fuel surcharges for #{fuel_surcharge.class.name.split("::").last} on #{fuel_surcharge.time_period}"
|
13
13
|
puts "# Fetched from #{fuel_surcharge.url}"
|
14
14
|
puts
|
15
|
-
puts "AIR = #{fuel_surcharge.air_percentage} / #{format
|
16
|
-
puts "ROAD = #{fuel_surcharge.road_percentage} / #{format
|
15
|
+
puts "AIR = #{fuel_surcharge.air_percentage} / #{format "%.4f", fuel_surcharge.air_multiplier}"
|
16
|
+
puts "ROAD = #{fuel_surcharge.road_percentage} / #{format "%.4f", fuel_surcharge.road_multiplier}"
|
17
17
|
puts
|
18
18
|
end
|
data/fuel_surcharge.gemspec
CHANGED
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
require "fuel_surcharge/version"
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
|
-
spec.required_ruby_version = "~> 2.
|
9
|
+
spec.required_ruby_version = "~> 2.5"
|
10
10
|
|
11
11
|
spec.name = "fuel_surcharge"
|
12
12
|
spec.version = FuelSurcharge::VERSION
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
"bug_tracker_uri" => "https://github.com/levups/fuel_surcharge/issues",
|
24
24
|
"changelog_uri" => "https://github.com/levups/fuel_surcharge/blob/master/CHANGELOG.md",
|
25
25
|
"homepage_uri" => "https://rubygems.org/gems/fuel_surcharge",
|
26
|
-
"source_code_uri" => "https://github.com/levups/fuel_surcharge"
|
26
|
+
"source_code_uri" => "https://github.com/levups/fuel_surcharge",
|
27
27
|
}
|
28
28
|
|
29
29
|
# Specify which files should be added to the gem when it is released.
|
@@ -42,7 +42,5 @@ Gem::Specification.new do |spec|
|
|
42
42
|
spec.add_development_dependency "minitest", "~> 5.0"
|
43
43
|
spec.add_development_dependency "minitest-stub_any_instance", "~> 1.0"
|
44
44
|
spec.add_development_dependency "rake", "~> 12.3"
|
45
|
-
|
46
|
-
spec.add_development_dependency "relaxed-rubocop", "~> 2.3.1"
|
47
|
-
spec.add_development_dependency "rubocop", "~> 0.62"
|
45
|
+
spec.add_development_dependency "standard", "~> 0.0.39"
|
48
46
|
end
|
@@ -2,17 +2,16 @@
|
|
2
2
|
|
3
3
|
require "fuel_surcharge/http_request"
|
4
4
|
require "fuel_surcharge/string_formatter"
|
5
|
+
require "fuel_surcharge/html_scanner"
|
5
6
|
|
6
7
|
module FuelSurcharge
|
7
8
|
class Chronopost
|
8
9
|
using StringFormatter
|
9
10
|
|
10
|
-
def
|
11
|
-
|
11
|
+
def time_period
|
12
|
+
periods.last
|
12
13
|
end
|
13
14
|
|
14
|
-
attr_reader :time_period, :air_percentage, :road_percentage
|
15
|
-
|
16
15
|
def air_multiplier
|
17
16
|
air_percentage&.to_multiplier
|
18
17
|
end
|
@@ -21,59 +20,54 @@ module FuelSurcharge
|
|
21
20
|
road_percentage&.to_multiplier
|
22
21
|
end
|
23
22
|
|
23
|
+
def air_percentage
|
24
|
+
@air_percentage ||= HTMLScanner.new(air_content).all("td")&.last
|
25
|
+
end
|
26
|
+
|
27
|
+
def road_percentage
|
28
|
+
@road_percentage ||= HTMLScanner.new(road_content).all("td")&.last
|
29
|
+
end
|
30
|
+
|
24
31
|
def url
|
25
32
|
"https://www.chronopost.fr/fr/surcharge-carburant"
|
26
33
|
end
|
27
34
|
|
28
35
|
private
|
29
36
|
|
30
|
-
def
|
31
|
-
@
|
32
|
-
.response
|
33
|
-
.to_s
|
34
|
-
.delete("\n")
|
35
|
-
.gsub(/\s+/, " ")
|
37
|
+
def periods
|
38
|
+
@periods ||= HTMLScanner.new(thead).all("th").map(&:strip_html).map(&:squish)
|
36
39
|
end
|
37
40
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
source_html.split("<table ")[1]
|
41
|
+
def air_content
|
42
|
+
rows.select { |e| e.include?("Aérien") }
|
42
43
|
end
|
43
44
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
tables.split("<h2>Principe</h2>").first
|
45
|
+
def road_content
|
46
|
+
rows.select { |e| e.include?("Routier") }
|
48
47
|
end
|
49
48
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
table.scan(%r{<thead>.*</thead>}).first
|
49
|
+
def rows
|
50
|
+
@rows ||= HTMLScanner.new(tbody).all("tr")
|
54
51
|
end
|
55
52
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
text = head.split(%r{</th>\s*<th}).last
|
60
|
-
text.match(%r{<p>(?<content>.*)</p>})
|
53
|
+
def thead
|
54
|
+
@thead ||= HTMLScanner.new(table).upcoming("thead")
|
61
55
|
end
|
62
56
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
table.scan(%r{<tbody><tr>.*</tr></tbody>}).first
|
57
|
+
def tbody
|
58
|
+
@tbody ||= HTMLScanner.new(table).upcoming("tbody")
|
67
59
|
end
|
68
60
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
61
|
+
def table
|
62
|
+
@table ||= HTMLScanner.new(source_html).upcoming("table")
|
63
|
+
end
|
72
64
|
|
73
|
-
|
74
|
-
@
|
75
|
-
|
76
|
-
|
65
|
+
def source_html
|
66
|
+
@source_html ||= HTTPRequest.new(url)
|
67
|
+
.response
|
68
|
+
.to_s
|
69
|
+
.delete("\n")
|
70
|
+
.gsub(/\s+/, " ")
|
77
71
|
end
|
78
72
|
end
|
79
73
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "strscan"
|
4
|
+
|
5
|
+
module FuelSurcharge
|
6
|
+
class HTMLScanner
|
7
|
+
def initialize(source)
|
8
|
+
@scanner = StringScanner.new(source.to_s)
|
9
|
+
end
|
10
|
+
|
11
|
+
def upcoming(tag)
|
12
|
+
return if @scanner.eos?
|
13
|
+
|
14
|
+
opening = "<#{tag}[^>]*>"
|
15
|
+
closing = "</#{tag}>"
|
16
|
+
return unless @scanner.exist?(/#{opening}/) && @scanner.exist?(/#{closing}/)
|
17
|
+
|
18
|
+
current_pos = @scanner.pos
|
19
|
+
@scanner.skip_until(/#{opening}/)
|
20
|
+
chunk = @scanner.scan_until(/#{closing}/).to_s
|
21
|
+
@scanner.pos = current_pos if chunk.empty?
|
22
|
+
chunk[0...chunk.size - closing.size].strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def all(tag)
|
26
|
+
chunks = []
|
27
|
+
return chunks if @scanner.eos?
|
28
|
+
|
29
|
+
while (chunk = upcoming(tag))
|
30
|
+
chunks << chunk
|
31
|
+
end
|
32
|
+
chunks
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -10,6 +10,19 @@ module FuelSurcharge
|
|
10
10
|
number = BigDecimal(clean_string)
|
11
11
|
1 + (number / 100).round(4)
|
12
12
|
end
|
13
|
+
|
14
|
+
# https://gist.github.com/awesome/225181
|
15
|
+
def strip_html
|
16
|
+
gsub!(%r{</?[^>]*>}, "")
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
# From ActiveSupport
|
21
|
+
def squish
|
22
|
+
gsub!(/[[:space:]]+/, " ")
|
23
|
+
strip!
|
24
|
+
self
|
25
|
+
end
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|
data/lib/fuel_surcharge/tnt.rb
CHANGED
@@ -7,27 +7,22 @@ module FuelSurcharge
|
|
7
7
|
class TNT
|
8
8
|
using StringFormatter
|
9
9
|
|
10
|
-
|
11
|
-
latest_road_values_position = 0
|
12
|
-
latest_air_values_position = extracted_values.size.div(2)
|
13
|
-
@road_values = extracted_values[latest_road_values_position]
|
14
|
-
@air_values = extracted_values[latest_air_values_position]
|
15
|
-
end
|
10
|
+
attr_accessor :current_month
|
16
11
|
|
17
|
-
def
|
18
|
-
|
12
|
+
def initialize(current_month: Date.today.month)
|
13
|
+
@current_month = current_month
|
19
14
|
end
|
20
15
|
|
21
16
|
def time_period
|
22
|
-
|
17
|
+
road_value&.first&.to_s
|
23
18
|
end
|
24
19
|
|
25
20
|
def road_percentage
|
26
|
-
|
21
|
+
road_value&.last&.to_s
|
27
22
|
end
|
28
23
|
|
29
24
|
def air_percentage
|
30
|
-
|
25
|
+
air_value&.last&.to_s
|
31
26
|
end
|
32
27
|
|
33
28
|
def road_multiplier
|
@@ -41,6 +36,7 @@ module FuelSurcharge
|
|
41
36
|
private
|
42
37
|
|
43
38
|
VALUES_REGEX = /Surcharge d[e\' ]+(.*) : (.*%)</.freeze
|
39
|
+
# Sample obtained structure :
|
44
40
|
# [
|
45
41
|
# [" novembre 2018 ", "12,10%"],
|
46
42
|
# ["octobre 2018 ", "11,95%"],
|
@@ -50,11 +46,43 @@ module FuelSurcharge
|
|
50
46
|
# [" septembre 2018 ", "17,50%"]
|
51
47
|
# ]
|
52
48
|
def extracted_values
|
53
|
-
|
49
|
+
response.to_s.scan(VALUES_REGEX)
|
50
|
+
end
|
51
|
+
|
52
|
+
def current_month_values
|
53
|
+
extracted_values.select { |month, value| month.include? current_month_name }
|
54
|
+
end
|
55
|
+
|
56
|
+
def air_value
|
57
|
+
current_month_values.last
|
54
58
|
end
|
55
59
|
|
60
|
+
def road_value
|
61
|
+
current_month_values.first
|
62
|
+
end
|
63
|
+
|
64
|
+
URL = "https://www.tnt.com/express/fr_fr/site/home/comment-expedier/facturation/surcharges/baremes-et-historiques.html"
|
56
65
|
def response
|
57
|
-
@response ||= HTTPRequest.new(
|
66
|
+
@response ||= HTTPRequest.new(URL).response
|
67
|
+
end
|
68
|
+
|
69
|
+
FRENCH_MONTHS_NAMES = %w[
|
70
|
+
janvier
|
71
|
+
février
|
72
|
+
mars
|
73
|
+
avril
|
74
|
+
mai
|
75
|
+
juin
|
76
|
+
juillet
|
77
|
+
août
|
78
|
+
septembre
|
79
|
+
octobre
|
80
|
+
novembre
|
81
|
+
décembre
|
82
|
+
].freeze
|
83
|
+
|
84
|
+
def current_month_name
|
85
|
+
FRENCH_MONTHS_NAMES[current_month - 1]
|
58
86
|
end
|
59
87
|
end
|
60
88
|
end
|
data/sideci.yml
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuel_surcharge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Maerten
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|
@@ -96,33 +96,19 @@ dependencies:
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '12.3'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
99
|
+
name: standard
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: 0.0.39
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: rubocop
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - "~>"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '0.62'
|
119
|
-
type: :development
|
120
|
-
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
requirements:
|
123
|
-
- - "~>"
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0.62'
|
111
|
+
version: 0.0.39
|
126
112
|
description: A simple gem to fetch transporters data every month.
|
127
113
|
email:
|
128
114
|
- bob@levups.com
|
@@ -132,9 +118,11 @@ executables:
|
|
132
118
|
extensions: []
|
133
119
|
extra_rdoc_files: []
|
134
120
|
files:
|
121
|
+
- ".circleci/config.yml"
|
122
|
+
- ".github_changelog_generator"
|
135
123
|
- ".gitignore"
|
136
124
|
- ".rubocop.yml"
|
137
|
-
- ".
|
125
|
+
- ".standard.yml"
|
138
126
|
- CHANGELOG.md
|
139
127
|
- Gemfile
|
140
128
|
- Gemfile.lock
|
@@ -149,10 +137,12 @@ files:
|
|
149
137
|
- lib/fuel_surcharge.rb
|
150
138
|
- lib/fuel_surcharge/chronopost.rb
|
151
139
|
- lib/fuel_surcharge/colissimo.rb
|
140
|
+
- lib/fuel_surcharge/html_scanner.rb
|
152
141
|
- lib/fuel_surcharge/http_request.rb
|
153
142
|
- lib/fuel_surcharge/string_formatter.rb
|
154
143
|
- lib/fuel_surcharge/tnt.rb
|
155
144
|
- lib/fuel_surcharge/version.rb
|
145
|
+
- sideci.yml
|
156
146
|
homepage: https://rubygems.org/gems/fuel_surcharge
|
157
147
|
licenses:
|
158
148
|
- MIT
|
@@ -169,14 +159,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
159
|
requirements:
|
170
160
|
- - "~>"
|
171
161
|
- !ruby/object:Gem::Version
|
172
|
-
version: '2.
|
162
|
+
version: '2.5'
|
173
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
164
|
requirements:
|
175
165
|
- - ">="
|
176
166
|
- !ruby/object:Gem::Version
|
177
167
|
version: '0'
|
178
168
|
requirements: []
|
179
|
-
rubygems_version: 3.0.
|
169
|
+
rubygems_version: 3.0.3
|
180
170
|
signing_key:
|
181
171
|
specification_version: 4
|
182
172
|
summary: Retrieve current month's Transporters' fuel surcharge
|
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
dist: xenial
|
5
|
-
|
6
|
-
before_install:
|
7
|
-
- gem update --system
|
8
|
-
- gem install bundler
|
9
|
-
# This is necessary to run `bundle exec rake` on Travis CI with Ruby 2.6
|
10
|
-
- gem install --user-install executable-hooks
|
11
|
-
|
12
|
-
rvm:
|
13
|
-
- 2.3
|
14
|
-
- 2.4
|
15
|
-
- 2.5
|
16
|
-
- 2.6
|