matheus 0.4.0 → 0.6.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 +4 -4
- data/.tool-versions +1 -1
- data/CHANGELOG.md +15 -0
- data/README.md +12 -6
- data/exe/convert-currency +7 -0
- data/lib/matheus/alert_me.rb +4 -0
- data/lib/matheus/convert_currency.rb +47 -0
- data/lib/matheus/q.rb +3 -3
- data/lib/matheus/qs.rb +2 -2
- data/lib/matheus/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e12186db7a0ecf5477d7456cd2917dd42c0051369c2c1d40af773295be4986a
|
4
|
+
data.tar.gz: 5171a3b830598f42fe2c25fd59873926b159c83691e0027faa5c6b3d684016ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e5a5e4abab785a8b7e72659bc5f5f5407fc23f518e5089587fb89461ad43fb37d4ab6e1b814893848e922ae97646148c5d27aa53c4db144a420a29ecd894796
|
7
|
+
data.tar.gz: 9d3f0453388968e8c6f80a4d7c39f8d0e6ab97135c52384c8a15653fb56c7a2a3ca673d47c518a182e0cfd0cb81c9b73861b42be1d34784df3f054e9613a1a18
|
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby 3.3.
|
1
|
+
ruby 3.3.5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.0]
|
4
|
+
|
5
|
+
_Released 2025-01-07_
|
6
|
+
|
7
|
+
- Allow specifying values on `convert-currency` command.
|
8
|
+
```sh
|
9
|
+
$ convert-currency 100 usd eur
|
10
|
+
```
|
11
|
+
|
12
|
+
## [0.5.0]
|
13
|
+
|
14
|
+
_Released 2024-12-27_
|
15
|
+
|
16
|
+
- Add `convert-currency` command.
|
17
|
+
|
3
18
|
## [0.4.0]
|
4
19
|
|
5
20
|
_Released 2024-10-02_
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Matheus
|
2
2
|
|
3
|
-
A
|
3
|
+
A collection of CLI tools I made for my own use.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -8,15 +8,21 @@ A bunch of CLI tools I made for my own use.
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
### `alert-me`
|
11
|
+
### [`alert-me`](./lib/matheus/alert_me.rb)
|
12
12
|
|
13
13
|
```sh
|
14
14
|
$ alert-me 'sleep 1 && echo "Done!"'
|
15
15
|
Done!
|
16
|
-
# plays a sound after the command finishes
|
17
16
|
```
|
18
17
|
|
19
|
-
### `
|
18
|
+
### [`convert-currency`](./lib/matheus/convert_currency.rb)
|
19
|
+
|
20
|
+
```sh
|
21
|
+
$ convert-currency usd eur
|
22
|
+
1 USD = 0.92 EUR
|
23
|
+
```
|
24
|
+
|
25
|
+
### [`date-of-last`](./lib/matheus/date_of_last.rb)
|
20
26
|
|
21
27
|
Prints the date of the last week day.
|
22
28
|
|
@@ -28,7 +34,7 @@ $ date-of-last sun
|
|
28
34
|
2024-02-11
|
29
35
|
```
|
30
36
|
|
31
|
-
### `q`
|
37
|
+
### [`q`](./lib/matheus/q.rb)
|
32
38
|
|
33
39
|
It expects a OPENAI_API_KEY environment variable to be set. It will try to load
|
34
40
|
it from a `.env` file at `~/.env`.
|
@@ -38,7 +44,7 @@ $ q "What is the capital of France?"
|
|
38
44
|
The capital of France is **Paris**
|
39
45
|
```
|
40
46
|
|
41
|
-
### `puts`
|
47
|
+
### [`puts`](./lib/matheus/puts.rb)
|
42
48
|
|
43
49
|
It evaluates the given Ruby code and prints the result. Active Support is
|
44
50
|
available.
|
data/lib/matheus/alert_me.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Matheus
|
6
|
+
# Usage:
|
7
|
+
# $ convert-currency 100 usd eur
|
8
|
+
# $ convert-currency 100 usd eur 2024-03-06
|
9
|
+
# $ convert-currency usd eur # defaults to 1
|
10
|
+
class ConvertCurrency < Command
|
11
|
+
def call(args)
|
12
|
+
amount, source, target, date = parse_args(args)
|
13
|
+
|
14
|
+
api_url = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@#{date}/v1/currencies/#{source}.min.json"
|
15
|
+
data = JSON.parse(Net::HTTP.get(URI(api_url)))
|
16
|
+
rate = data.dig(source.downcase, target.downcase)
|
17
|
+
|
18
|
+
if rate
|
19
|
+
converted = amount * rate
|
20
|
+
puts "#{amount} #{source.upcase} = #{ActiveSupport::NumberHelper.number_to_currency(converted, unit: "")} #{target.upcase}"
|
21
|
+
else
|
22
|
+
Failure("Conversion rate from #{source.upcase} to #{target.upcase} not found")
|
23
|
+
end
|
24
|
+
rescue => e
|
25
|
+
Failure(e.message)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def parse_args(args)
|
31
|
+
first_arg = args.fetch(0) { raise "Missing amount or source currency" }
|
32
|
+
|
33
|
+
if (amount = Float(first_arg) rescue nil)
|
34
|
+
source = args.fetch(1) { raise "Missing source currency" }
|
35
|
+
target = args.fetch(2) { raise "Missing target currency" }
|
36
|
+
date = args.fetch(3, Date.today)
|
37
|
+
else
|
38
|
+
amount = 1.0
|
39
|
+
source = first_arg
|
40
|
+
target = args.fetch(1) { raise "Missing target currency" }
|
41
|
+
date = args.fetch(2, Date.today)
|
42
|
+
end
|
43
|
+
|
44
|
+
[amount, source, target, date]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/matheus/q.rb
CHANGED
@@ -15,7 +15,7 @@ module Matheus
|
|
15
15
|
existing_entry = search_question_in_history(question)
|
16
16
|
|
17
17
|
if existing_entry && use_existing_answer?
|
18
|
-
answer = existing_entry[
|
18
|
+
answer = existing_entry["answer"]
|
19
19
|
else
|
20
20
|
answer = ask_llm(question)
|
21
21
|
save_qa(question, answer)
|
@@ -55,7 +55,7 @@ module Matheus
|
|
55
55
|
|
56
56
|
def save_qa(question, answer)
|
57
57
|
history = load_history
|
58
|
-
history << {
|
58
|
+
history << {question:, answer:, timestamp: Time.now.to_s}
|
59
59
|
File.write(QUESTION_HISTORY_FILE, JSON.pretty_generate(history))
|
60
60
|
end
|
61
61
|
|
@@ -64,7 +64,7 @@ module Matheus
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def search_question_in_history(question)
|
67
|
-
load_history.reverse.find { |entry| entry[
|
67
|
+
load_history.reverse.find { |entry| entry["question"].downcase.strip == question.downcase.strip }
|
68
68
|
end
|
69
69
|
|
70
70
|
def use_existing_answer?
|
data/lib/matheus/qs.rb
CHANGED
@@ -17,13 +17,13 @@ module Matheus
|
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
|
+
|
20
21
|
def choices
|
21
22
|
history.map do |entry|
|
22
|
-
{entry[
|
23
|
+
{entry["question"] => entry["answer"]}
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
27
|
def history
|
28
28
|
@history ||= File.exist?(QUESTION_HISTORY_FILE) ? JSON.parse(File.read(QUESTION_HISTORY_FILE)) : []
|
29
29
|
end
|
data/lib/matheus/version.rb
CHANGED
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
|
+
version: 0.6.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:
|
11
|
+
date: 2025-01-07 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.
|
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.
|