curex 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15cf553522fa4a17bfbbe4ed35c35704645a64ae
4
+ data.tar.gz: f214ff81d0d1a4394bec706c161e0dc0cf47afa4
5
+ SHA512:
6
+ metadata.gz: 8b8c8ee710b6f789fe4fde19e9837e6db21b2976cd95df5233523d91f626afa9dea725f080819d393b991d6e7bd5faf92f69648911f248f245e02cb7021b9edf
7
+ data.tar.gz: 4b9a531203d9ebf4c3e30f81e688179e672b728fd48fef2f117030bbaa1b5899b2922d786e744a8fd74fc7f3dff1650adf6b0ec2823cc2206dbefea43739896c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
@@ -0,0 +1,61 @@
1
+ # CurEx
2
+
3
+ CURrency EXchange command line utility.
4
+
5
+ This is a proof of concept to use [`hanami-cli`](https://github.com/hanami/cli)
6
+
7
+ ## Installation
8
+
9
+ ```shell
10
+ $ gem install curex
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```shell
16
+ $ curex --help
17
+ Commands:
18
+ curex convert AMOUNT FROM TO # Convert an amount from one currency to another
19
+ ```
20
+
21
+ ```shell
22
+ $ curex convert --help
23
+ Command:
24
+ curex convert
25
+
26
+ Usage:
27
+ curex convert AMOUNT FROM TO
28
+
29
+ Description:
30
+ Convert an amount from one currency to another
31
+
32
+ Arguments:
33
+ AMOUNT # REQUIRED the amount of money to convert
34
+ FROM # REQUIRED the starting currency
35
+ TO # REQUIRED the final currency
36
+
37
+ Options:
38
+ --help, -h # Print this help
39
+
40
+ Examples:
41
+ curex convert 100 USD EUR # convert 100 USD to EUR
42
+ ```
43
+
44
+ ```shell
45
+ $ curex convert 100 USD EUR
46
+ 100 USD == 84,90 EUR
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ 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).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jodosha/curex.
58
+
59
+ ## Copyright
60
+
61
+ [Luca Guidi](https://lucaguidi.com) © 2017 - Released under the MIT License
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "curex"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path("../lib", __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "curex/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "curex"
10
+ spec.version = Curex::VERSION
11
+ spec.authors = ["Luca Guidi"]
12
+ spec.email = ["me@lucaguidi.com"]
13
+
14
+ spec.summary = "CUrrency EXchange"
15
+ spec.description = "CUrrency EXchange (curex) command line"
16
+ spec.homepage = "https://lucaguidi.com"
17
+ spec.license = "MIT"
18
+
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "hanami-cli", "0.1.0.beta3"
29
+ spec.add_dependency "google_currency", "~> 3.4"
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.15"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ begin
5
+ require "bundler/setup"
6
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
7
+ end
8
+
9
+ require "curex"
10
+
11
+ Curex::CLI.new.call
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/cli"
4
+ require "bigdecimal"
5
+ require "money"
6
+ require "money/bank/google_currency"
7
+
8
+ module Curex
9
+ require "curex/version"
10
+
11
+ class Converter
12
+ SCALE = 100
13
+
14
+ def initialize
15
+ Money.use_i18n = false
16
+ Money.default_bank = Money::Bank::GoogleCurrency.new
17
+ end
18
+
19
+ def call(amount, from, to)
20
+ money = Money.new(amount.to_d * SCALE, from)
21
+ money.exchange_to(to)
22
+ end
23
+ end
24
+
25
+ class CLI
26
+ def call(*args)
27
+ Hanami::CLI.new(Commands).call(*args)
28
+ end
29
+
30
+ module Commands
31
+ extend Hanami::CLI::Registry
32
+
33
+ class Convert < Hanami::CLI::Command
34
+ desc "Convert an amount from one currency to another"
35
+
36
+ argument :amount, required: true, desc: "the amount of money to convert"
37
+ argument :from, required: true, desc: "the starting currency"
38
+ argument :to, required: true, desc: "the final currency"
39
+
40
+ example [
41
+ "100 USD EUR # convert 100 USD to EUR"
42
+ ]
43
+
44
+ def call(amount:, from:, to:, **)
45
+ result = Converter.new.call(amount, from, to)
46
+ puts "#{amount} #{from} == #{result} #{to}"
47
+ end
48
+ end
49
+
50
+ register "convert", Convert, aliases: ["c"]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Curex
4
+ VERSION = "0.1.0.beta1"
5
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: curex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Luca Guidi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hanami-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0.beta3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0.beta3
27
+ - !ruby/object:Gem::Dependency
28
+ name: google_currency
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: CUrrency EXchange (curex) command line
70
+ email:
71
+ - me@lucaguidi.com
72
+ executables:
73
+ - curex
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - curex.gemspec
84
+ - exe/curex
85
+ - lib/curex.rb
86
+ - lib/curex/version.rb
87
+ homepage: https://lucaguidi.com
88
+ licenses:
89
+ - MIT
90
+ metadata:
91
+ allowed_push_host: https://rubygems.org
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">"
104
+ - !ruby/object:Gem::Version
105
+ version: 1.3.1
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.6.13
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: CUrrency EXchange
112
+ test_files: []