matheus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c05656b0745325e8c8f1335de5aa607be0352e39c973cd120b904986e213308d
4
+ data.tar.gz: de0ae216763330fc255bb5ca5290da2f60e8434feebf432eeb0273cb43aa676b
5
+ SHA512:
6
+ metadata.gz: 9e8de67cd9b1a0d1b87d2900701f4d09014e5fd18f790b85bf69ba71cd731f784e8fafff53ae22ca44f92fab1c71bf5281336ccbb69790b9fa0647572ddcd507
7
+ data.tar.gz: a49214eacc6b2135b1e1b7a903b68026a5fee9776d316270e8d8ea9f8c36ac3b06400fe540413a9c84ba402d29a3b293e59bc092956cdf96e3c9aa37018f2b97
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.2.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-19
4
+
5
+ - Initial release. It includes the commands:
6
+
7
+ ### `puts`: evals the given Ruby code and prints the result
8
+
9
+ ```sh
10
+ $ puts 1 + 1
11
+ 2
12
+ ```
13
+
14
+ ### `date-of-last`: prints the date of the last week day
15
+
16
+ ```sh
17
+ $ date-of-last monday
18
+ 2024-02-12
19
+ ```
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Matheus Richard
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,15 @@
1
+ # Matheus
2
+
3
+ A bunch of CLI tools I made for my own use.
4
+
5
+ ## Installation
6
+
7
+ $ gem install matheus
8
+
9
+ ## Contributing
10
+
11
+ Probably not accepting contributions at the moment, but feel free to open an issue if you have any ideas or suggestions.
12
+
13
+ ## License
14
+
15
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/exe/date-of-last ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "matheus"
6
+
7
+ Matheus::DateOfLast.call(ARGV[0])
data/exe/puts ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "matheus"
6
+
7
+ Matheus::Puts.call ARGV
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Matheus
4
+ class Command
5
+ include Result::Methods
6
+ extend StringFormat
7
+
8
+ def self.call(argv)
9
+ new
10
+ .call(argv)
11
+ .then { Result.from(_1) } # ensure it's a Result object
12
+ .on_failure { |error_msg| abort error(error_msg) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+
5
+ module Matheus
6
+ class DateOfLast < Command
7
+ def call(day_name)
8
+ day_name = day_name.to_s
9
+
10
+ target_wday = wday_for(day_name) or return Failure("invalid day name: #{day_name}")
11
+ date = Date.today
12
+ one_day_ago = (date - 1)
13
+ one_week_ago = date - 7
14
+ date = one_day_ago.downto(one_week_ago).find { _1.wday == target_wday }
15
+
16
+ puts date
17
+ end
18
+
19
+ private
20
+
21
+ def wday_for(day_name)
22
+ Date::DAYNAMES.index(day_name.capitalize) || Date::ABBR_DAYNAMES.index(day_name.capitalize)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "active_support"
5
+ require "active_support/core_ext"
6
+
7
+ module Matheus
8
+ class Puts < Command
9
+ def call(argv)
10
+ puts eval(argv.join(" ")) # standard:disable Security/Eval
11
+ rescue Exception => e # standard:disable Lint/RescueException
12
+ Failure(e.message)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Matheus
4
+ module Result
5
+ Success = Data.define(:value) do
6
+ def success? = true
7
+
8
+ def failure? = false
9
+
10
+ def on_success = yield(value)
11
+
12
+ def on_failure = self
13
+
14
+ def error = nil
15
+
16
+ def inspect = "Success(#{value.inspect})"
17
+ end
18
+
19
+ Failure = Data.define(:error) do
20
+ def success? = false
21
+
22
+ def failure? = true
23
+
24
+ def on_success = self
25
+
26
+ def on_failure = yield(error)
27
+
28
+ def value = raise "Can't call #value on a #{self.class} object. Object is #{inspect}"
29
+
30
+ def inspect = "Failure(#{error.inspect})"
31
+ end
32
+
33
+ module Methods
34
+ def Success(value) = Result::Success.new(value)
35
+
36
+ def Failure(error) = Result::Failure.new(error)
37
+ end
38
+
39
+ def self.from(value)
40
+ if value.is_a?(Success) || value.is_a?(Failure)
41
+ value
42
+ else
43
+ Success.new(value)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Matheus
4
+ module StringFormat
5
+ def error(message)
6
+ bold(red("Error: ") + message)
7
+ end
8
+
9
+ def red(text)
10
+ "\e[31m#{text}\e[0m"
11
+ end
12
+
13
+ def bold(text)
14
+ "\e[1m#{text}\e[22m"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Matheus
4
+ VERSION = "0.1.0"
5
+ end
data/lib/matheus.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zeitwerk"
4
+
5
+ Zeitwerk::Loader.for_gem.setup
6
+
7
+ module Matheus
8
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matheus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matheus Richard
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.6.13
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.13
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 7.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 7.1.0
41
+ description: A bunch of CLI tools I made for my own use.
42
+ email:
43
+ - matheusrichardt@gmail.com
44
+ executables:
45
+ - date-of-last
46
+ - puts
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".rspec"
51
+ - ".tool-versions"
52
+ - CHANGELOG.md
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - exe/date-of-last
57
+ - exe/puts
58
+ - lib/matheus.rb
59
+ - lib/matheus/command.rb
60
+ - lib/matheus/date_of_last.rb
61
+ - lib/matheus/puts.rb
62
+ - lib/matheus/result.rb
63
+ - lib/matheus/string_format.rb
64
+ - lib/matheus/version.rb
65
+ homepage: https://github.com/MatheusRich/matheus
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/MatheusRich/matheus
70
+ source_code_uri: https://github.com/MatheusRich/matheus
71
+ changelog_uri: https://github.com/MatheusRich/matheus/blob/main/CHANGELOG.md
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.2.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.4.1
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: A bunch of CLI tools I made for my own use.
91
+ test_files: []