matheus 0.5.0 → 0.6.1
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/CHANGELOG.md +9 -0
- data/README.md +5 -6
- data/lib/matheus/alert_me.rb +3 -3
- data/lib/matheus/convert_currency.rb +29 -11
- data/lib/matheus/q.rb +3 -3
- data/lib/matheus/qs.rb +2 -2
- data/lib/matheus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e859fa5b5a161ef7c0d97e5519a99a54337a19706b50144f2ac86792694067a1
|
4
|
+
data.tar.gz: e03c984893f614ef40b84197e6d6016cee38ed6ca306b89a1057885ea040e76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79ae596c0b3363e865a3bd664ae7a174ba231d6cec6c41bb29358402e145e9ad4dee6ed6ee7b96fb95420f935b2377f4ae81c0445f92188f3d77a54fd31d9d80
|
7
|
+
data.tar.gz: 7cffe1c0d148e3f4310e6876f649ba7dd7e8767eb792132f211c0f6b164b7928e625f2b58577299eaba363358962a8363a3ea991cf24aecd59714d831d9d0471
|
data/CHANGELOG.md
CHANGED
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,12 +8,11 @@ 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)
|
@@ -23,7 +22,7 @@ $ convert-currency usd eur
|
|
23
22
|
1 USD = 0.92 EUR
|
24
23
|
```
|
25
24
|
|
26
|
-
### `date-of-last`
|
25
|
+
### [`date-of-last`](./lib/matheus/date_of_last.rb)
|
27
26
|
|
28
27
|
Prints the date of the last week day.
|
29
28
|
|
@@ -35,7 +34,7 @@ $ date-of-last sun
|
|
35
34
|
2024-02-11
|
36
35
|
```
|
37
36
|
|
38
|
-
### `q`
|
37
|
+
### [`q`](./lib/matheus/q.rb)
|
39
38
|
|
40
39
|
It expects a OPENAI_API_KEY environment variable to be set. It will try to load
|
41
40
|
it from a `.env` file at `~/.env`.
|
@@ -45,7 +44,7 @@ $ q "What is the capital of France?"
|
|
45
44
|
The capital of France is **Paris**
|
46
45
|
```
|
47
46
|
|
48
|
-
### `puts`
|
47
|
+
### [`puts`](./lib/matheus/puts.rb)
|
49
48
|
|
50
49
|
It evaluates the given Ruby code and prints the result. Active Support is
|
51
50
|
available.
|
data/lib/matheus/alert_me.rb
CHANGED
@@ -1,29 +1,47 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
require "date"
|
4
4
|
|
5
5
|
module Matheus
|
6
6
|
# Usage:
|
7
|
-
# $ convert-currency usd eur
|
8
|
-
# $ convert-currency usd eur 2024-03-06
|
7
|
+
# $ convert-currency 100 usd eur
|
8
|
+
# $ convert-currency 100 usd eur 2024-03-06
|
9
|
+
# $ convert-currency usd eur # defaults to 1
|
9
10
|
class ConvertCurrency < Command
|
10
11
|
def call(args)
|
11
|
-
source = args
|
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"
|
12
|
+
amount, source, target, date = parse_args(args)
|
16
13
|
|
14
|
+
api_url = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@#{date}/v1/currencies/#{source}.min.json"
|
17
15
|
data = JSON.parse(Net::HTTP.get(URI(api_url)))
|
18
16
|
rate = data.dig(source.downcase, target.downcase)
|
19
17
|
|
20
18
|
if rate
|
21
|
-
|
19
|
+
converted = amount * rate
|
20
|
+
puts "#{amount} #{source.upcase} = #{ActiveSupport::NumberHelper.number_to_currency(converted, unit: "")} #{target.upcase}"
|
22
21
|
else
|
23
22
|
Failure("Conversion rate from #{source.upcase} to #{target.upcase} not found")
|
24
23
|
end
|
25
24
|
rescue => e
|
26
25
|
Failure(e.message)
|
27
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) # standard:disable Style/RescueModifier
|
34
|
+
source = args.fetch(1) { raise "Missing source currency" }
|
35
|
+
target = args.fetch(2) { raise "Missing target currency" }
|
36
|
+
date = Date.parse(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 = Date.parse(args.fetch(2, Date.today))
|
42
|
+
end
|
43
|
+
|
44
|
+
[amount, source, target, date]
|
45
|
+
end
|
28
46
|
end
|
29
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.1
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|