matheus 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f0188994d160b9cfc3ce6ab06610e4f42102ddf828dc01e1c917cdf02ac77c6
4
- data.tar.gz: 0cf90a3177f25047f2b15fcf5198eb0de8ea3439116107576b7fdd7daab5bddf
3
+ metadata.gz: 1aae1525835c65b5020012db937256f508f67fbb67662cd2ccf8ff73057ba6a0
4
+ data.tar.gz: 4d16cc4bebdbf0044a8a68455487580fc80c391fee5571de08d8ac33c6df7133
5
5
  SHA512:
6
- metadata.gz: 364f6273dfdbc464d491b3ce29d670351c5c4c007524c0aa6ad46e1d44e810bf4e7dfa083821a20ae2f0058d01e45a601f7b68c70b9d42ed156df3e6205af895
7
- data.tar.gz: d8c641cbaeca884aff2d5782b0abbe720ddaf08af0057676d85ea9bdb9bb0adff33f81c8b158d8a18ba32879dd2f7e30f667c9e400ca4e9862befcae44409366
6
+ metadata.gz: 389ca6376f66e3a04ca92e9f969469c48f063705b792ab2f7e312a51bfe7b1303a65643de9e39586e394f2fdb9e54030c71191b38beff8b01b94eac77bc01e0d
7
+ data.tar.gz: 8b5d9c3055ee080259e314e785d18e661522bcda62964246cef86642d33ec72bd06a1e64dbc8e568a50999bdd1659ac9dd1dbce4ac5c6a78cc2d39289228dd40
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.3.4
1
+ ruby 3.3.5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0]
4
+
5
+ _Released 2024-12-27_
6
+
7
+ - Add `convert-currency` command.
8
+
3
9
  ## [0.4.0]
4
10
 
5
11
  _Released 2024-10-02_
data/README.md CHANGED
@@ -16,6 +16,13 @@ Done!
16
16
  # plays a sound after the command finishes
17
17
  ```
18
18
 
19
+ ### [`convert-currency`](./lib/matheus/convert_currency.rb)
20
+
21
+ ```sh
22
+ $ convert-currency usd eur
23
+ 1 USD = 0.92 EUR
24
+ ```
25
+
19
26
  ### `date-of-last`
20
27
 
21
28
  Prints the date of the last week day.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "matheus"
6
+
7
+ Matheus::ConvertCurrency.call ARGV
@@ -1,3 +1,7 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'date'
4
+
1
5
  module Matheus
2
6
  class AlertMe < Command
3
7
  # Usage:
@@ -0,0 +1,29 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ module Matheus
6
+ # Usage:
7
+ # $ convert-currency usd eur
8
+ # $ convert-currency usd eur 2024-03-06
9
+ class ConvertCurrency < Command
10
+ def call(args)
11
+ source = args.fetch(0) { raise "Missing source currency" }
12
+ target = args.fetch(1) { raise "Missing target currency" }
13
+ date = args.fetch(2, Date.today)
14
+
15
+ api_url = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@#{date}/v1/currencies/#{source}.json"
16
+
17
+ data = JSON.parse(Net::HTTP.get(URI(api_url)))
18
+ rate = data.dig(source.downcase, target.downcase)
19
+
20
+ if rate
21
+ puts "1 #{source.upcase} = #{ActiveSupport::NumberHelper.number_to_currency(rate, unit: "")} #{target.upcase}"
22
+ else
23
+ Failure("Conversion rate from #{source.upcase} to #{target.upcase} not found")
24
+ end
25
+ rescue => e
26
+ Failure(e.message)
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Matheus
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-02 00:00:00.000000000 Z
11
+ date: 2024-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -113,6 +113,7 @@ email:
113
113
  - matheusrichardt@gmail.com
114
114
  executables:
115
115
  - alert-me
116
+ - convert-currency
116
117
  - date-of-last
117
118
  - puts
118
119
  - q
@@ -127,6 +128,7 @@ files:
127
128
  - README.md
128
129
  - Rakefile
129
130
  - exe/alert-me
131
+ - exe/convert-currency
130
132
  - exe/date-of-last
131
133
  - exe/puts
132
134
  - exe/q
@@ -134,6 +136,7 @@ files:
134
136
  - lib/matheus.rb
135
137
  - lib/matheus/alert_me.rb
136
138
  - lib/matheus/command.rb
139
+ - lib/matheus/convert_currency.rb
137
140
  - lib/matheus/date_of_last.rb
138
141
  - lib/matheus/puts.rb
139
142
  - lib/matheus/q.rb
@@ -163,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
166
  - !ruby/object:Gem::Version
164
167
  version: '0'
165
168
  requirements: []
166
- rubygems_version: 3.5.11
169
+ rubygems_version: 3.5.16
167
170
  signing_key:
168
171
  specification_version: 4
169
172
  summary: A bunch of CLI tools I made for my own use.