freight_calc 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 575245a16377574863175af1a42c30042a5b3f391709540e10ef41adb0eef234
4
+ data.tar.gz: 96190d039cc49af35ca2cf5f1400f591a593cdb377c6fdda6806a32a50ccf40d
5
+ SHA512:
6
+ metadata.gz: 1bb4e40ae3b06c69ce3603c993e21973ec594853a10f4d4345c62b847cc8234d7acf7b6c3fba3818729a9185e8098c09162dcec084c5698d733ec7d38c9dafc3
7
+ data.tar.gz: b0dd951b0c34d275a2cf7626dd8c0da99d33dcc2c55af41d1d02d4567f66c0802b0d8a2924a7d21d479138563b7fbd57aefe93c4f9ef8f4076163153c6ba6d5a
data/.gem_release.yml ADDED
@@ -0,0 +1,3 @@
1
+ bump:
2
+ file: lib/freight_calc/version.rb
3
+ skip_ci: true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ require:
2
+ - standard
3
+
4
+ inherit_gem:
5
+ standard: config/base.yml
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - 'bin/*'
10
+ - 'tmp/**/*'
11
+ - 'Gemfile'
12
+ - 'vendor/**/*'
13
+ - 'gemfiles/**/*'
14
+ - 'lib/.rbnext/**/*'
15
+ - 'lib/generators/**/templates/*.rb'
16
+ - '.github/**/*'
17
+ DisplayCopNames: true
18
+ SuggestExtensions: false
19
+ NewCops: disable
20
+ TargetRubyVersion: 3.0
21
+
22
+ Style/StringLiterals:
23
+ Enabled: true
24
+ EnforcedStyle: double_quotes
25
+
26
+ Style/StringLiteralsInInterpolation:
27
+ Enabled: true
28
+ EnforcedStyle: double_quotes
29
+
30
+ Style/FrozenStringLiteralComment:
31
+ Enabled: false
32
+
33
+ Layout/LineLength:
34
+ Max: 120
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --markup markdown
2
+ --markup-provider redcarpet
3
+ --charset utf-8
4
+ --readme README.md
5
+ -
6
+ README.md
7
+ LICENSE
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-06-06
4
+
5
+ - Initial release ([@wishka][])
6
+
7
+ [@wishka]: https://github.com/wishka
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at andrew.kancev@jetruby.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Andrew Kancev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ [![Gem Version](https://badge.fury.io/rb/freight_calc.svg)](https://rubygems.org/gems/freight_calc)
2
+ [![Build](https://github.com/wishka/freight_calc/workflows/Build/badge.svg)](https://github.com/wishka/freight_calc/actions)
3
+
4
+ # Freight Calculator
5
+
6
+ It will help you calculate the distance and cost of cargo delivery. Thanks to simple settings, it can become an indispensable tool for both private couriers and large companies. If you'll needed more sensitive settings look at the source code to make it.
7
+
8
+ ## Installation
9
+
10
+ Install the gem and add to the application's Gemfile by executing:
11
+
12
+ $ bundle add freight_calc
13
+
14
+ If bundler is not being used to manage dependencies, install the gem by executing:
15
+
16
+ $ gem install freight_calc
17
+
18
+ ## Usage
19
+
20
+ Add the gem to your Gemfile:
21
+
22
+ ```ruby
23
+ gem "freight_calc"
24
+ ```
25
+
26
+ Then you'll need to get API key from https://distancematrix.ai/ and put this API_KEY in your .env file as DISTANCE_API_KEY
27
+
28
+ Example code to use :
29
+
30
+ ```ruby
31
+ ...
32
+
33
+ def calculate_price
34
+ calculator = DistCalculator.new(weight, length, width, height, origin, destination)
35
+ calculator.calculate_price
36
+ end
37
+
38
+ def calculate_distance
39
+ dist_calculator = DistCalculator.new(weight, length, width, height, origin, destination)
40
+ dist_calculator.calculate_distance / 1000
41
+ end
42
+ ...
43
+
44
+ ```
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/freight_calc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/freight_calc/blob/master/CODE_OF_CONDUCT.md).
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
59
+
60
+ ## Code of Conduct
61
+
62
+ Everyone interacting in the FreightCalc project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/freight_calc/blob/master/CODE_OF_CONDUCT.md).
data/RELEASING.md ADDED
@@ -0,0 +1,43 @@
1
+ # How to release a gem
2
+
3
+ This document describes a process of releasing a new version of a gem.
4
+
5
+ 1. Bump version.
6
+
7
+ ```sh
8
+ git commit -m "Bump 1.<x>.<y>"
9
+ ```
10
+
11
+ We're (kinda) using semantic versioning:
12
+
13
+ - Bugfixes should be released as fast as possible as patch versions.
14
+ - New features could be combined and released as minor or patch version upgrades (depending on the _size of the feature_—it's up to maintainers to decide).
15
+ - Breaking API changes should be avoided in minor and patch releases.
16
+ - Breaking dependencies changes (e.g., dropping older Ruby support) could be released in minor versions.
17
+
18
+ How to bump a version:
19
+
20
+ - Change the version number in `lib/freight_calc/version.rb` file.
21
+ - Update the changelog (add new heading with the version name and date).
22
+ - Update the installation documentation if necessary (e.g., during minor and major updates).
23
+
24
+ 2. Push code to GitHub and make sure CI passes.
25
+
26
+ ```sh
27
+ git push
28
+ ```
29
+
30
+ 3. Release a gem.
31
+
32
+ ```sh
33
+ gem release -t
34
+ git push --tags
35
+ ```
36
+
37
+ We use [gem-release](https://github.com/svenfuchs/gem-release) for publishing gems with a single command:
38
+
39
+ ```sh
40
+ gem release -t
41
+ ```
42
+
43
+ Don't forget to push tags and write release notes on GitHub (if necessary).
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "yard"
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ YARD::Rake::YardocTask.new
10
+
11
+ begin
12
+ require "rubocop/rake_task"
13
+ RuboCop::RakeTask.new
14
+
15
+ RuboCop::RakeTask.new("rubocop:md") do |task|
16
+ task.options << %w[-c .rubocop-md.yml]
17
+ end
18
+ rescue LoadError
19
+ task(:rubocop) {}
20
+ task("rubocop:md") {}
21
+ end
22
+
23
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org" do
2
+
3
+
4
+ gem "standard", "~> 1.0"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FreightCalc
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "freight_calc/version"
4
+
5
+ module FreightCalc
6
+ class Error < StandardError; end
7
+
8
+ require "json"
9
+ require "net/http"
10
+
11
+ class DistCalculator
12
+ def initialize(weight, length, width, height, origin, destination)
13
+ @weight = weight
14
+ @length = length
15
+ @width = width
16
+ @height = height
17
+ @origin = origin
18
+ @destination = destination
19
+ end
20
+
21
+ def calculate_distance
22
+ url = "https://api.distancematrix.ai/maps/api/distancematrix/json?origins=#{@origin}&destinations=#{@destination}&key=#{ENV["DISTANCE_API_KEY"]}"
23
+ uri = URI(url)
24
+ response = Net::HTTP.get(uri)
25
+ data = JSON.parse(response)
26
+
27
+ unless data && data["rows"] && data["rows"][0] && data["rows"][0]["elements"] && data["rows"][0]["elements"][0] && data["rows"][0]["elements"][0]["distance"] && data["rows"][0]["elements"][0]["distance"]["value"]
28
+ return nil
29
+ end
30
+
31
+ data["rows"][0]["elements"][0]["distance"]["value"]
32
+
33
+ # Handle the case when the data is not in the expected format
34
+ end
35
+
36
+ def calculate_price
37
+ distance = calculate_distance
38
+ volume = @length * @width * @height / 1_000_000.0 # convert cm^3 to m^3
39
+
40
+ price = if volume < 1
41
+ distance * 1
42
+ elsif volume >= 1 && @weight <= 10
43
+ distance * 2
44
+ else
45
+ distance * 3
46
+ end
47
+
48
+ {weight: @weight, length: @length, width: @width, height: @height, distance: distance, price: price}
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ desc "Spec all functionality of gem"
2
+
3
+ task :spec_all do
4
+ system("rspec spec/*/")
5
+ end
@@ -0,0 +1,4 @@
1
+ module FreightCalc
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freight_calc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kancev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.36
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.36
41
+ description: Write a longer description or delete this line.
42
+ email:
43
+ - andrew.kancev@jetruby.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gem_release.yml"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".yardopts"
52
+ - CHANGELOG.md
53
+ - CODE_OF_CONDUCT.md
54
+ - LICENSE.txt
55
+ - README.md
56
+ - RELEASING.md
57
+ - Rakefile
58
+ - gemfiles/rubocop.gemfile
59
+ - lib/freight_calc.rb
60
+ - lib/freight_calc/version.rb
61
+ - lib/tasks/run_tests.rake
62
+ - sig/freight_calc.rbs
63
+ homepage:
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ bug_tracker_uri: https://github.com/wishka/freight_calc/issues
68
+ changelog_uri: https://github.com/wishka/freight_calc/blob/master/CHANGELOG.md
69
+ documentation_uri: https://github.com/wishka/freight_calc
70
+ homepage_uri: https://github.com/wishka/freight_calc
71
+ source_code_uri: https://github.com/wishka/freight_calc
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.0.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.1.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Write a short summary, because RubyGems requires one.
91
+ test_files: []