cron_describer 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a72eb20b1b1637fff6bf409289667313e77d8d6524315099b8b4620ab4f0c72c
4
+ data.tar.gz: 5c4da5ac5775ecb2d9b439ecfc8a1f0ada6ccde97a75acc924366a9b6f4a9c0f
5
+ SHA512:
6
+ metadata.gz: be4cc3cd5ff45fb9a8865b070ff1a831c9c709573d077731fb5c26ed6729b0879791c7943dcaceb7c9ea94bf0d6727a9948a3bfcf5c84608c2d15a389ba14c2c
7
+ data.tar.gz: daae3b954bcc707b8dab8228bb2749d6e7a019d779ae05999bfe182f3aa56f7b94dee588dc1115f31232fde4b9f8b64887d533ad9b154e273318cd28b3147108
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-08
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Aleksander Lopez
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,54 @@
1
+ # CronDescriber
2
+
3
+ CronDescriber is a simple Ruby gem that converts cron schedule strings into human-readable time descriptions. It can help you describe complex cron schedules in a way that is easy to understand.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cron_describer'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install cron_describer
23
+ ```
24
+
25
+
26
+ ## Usage
27
+
28
+ Here is a basic example of how to use the CronDescriber gem:
29
+
30
+ ```ruby
31
+ require 'cron_describer'
32
+
33
+ cron_schedule = "30 6 1 */3 *"
34
+ description = CronDescriber.parse(cron_schedule)
35
+ puts description
36
+ # Output: "At 6:30 AM, on day 1 of the month, every 3 months"
37
+ ```
38
+
39
+ You can pass any valid cron schedule string to the describe_cron method to get a human-readable description.
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also `run bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ 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.
46
+
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/logicalgroove/cron_describer. This project is intended to be a safe, welcoming space for collaboration,
51
+
52
+ ## License
53
+
54
+ 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
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/cron_describer/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cron_describer"
7
+ spec.version = CronDescriber::VERSION
8
+ spec.authors = ["Aleksander Lopez Yazikov"]
9
+ spec.email = ["webodessa@gmail.com"]
10
+
11
+ spec.summary = "A gem to convert cron schedule strings into human-readable time"
12
+ spec.description = "A Ruby gem that takes a cron schedule string and converts it into a human-readable time description."
13
+ spec.homepage = "https://github.com/logicalgroove/cron_describer"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/logicalgroove/cron_describer"
19
+ spec.metadata["changelog_uri"] = "https://github.com/logicalgroove/cron_describer"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronDescriber
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cron_describer/version"
4
+
5
+ module CronDescriber
6
+ class Error < StandardError; end
7
+
8
+ def self.parse(cron_schedule)
9
+ days_of_week = {0 => "Sunday", 1 => "Monday", 2 => "Tuesday", 3 => "Wednesday", 4 => "Thursday", 5 => "Friday", 6 => "Saturday"}
10
+
11
+ minute, hour, day_of_month, month, day_of_week = cron_schedule.split(" ")
12
+
13
+ time_string = ""
14
+ day_string = ""
15
+ month_string = ""
16
+
17
+ # For time string
18
+ if minute == "0" && hour != "*"
19
+ time_string = "At #{hour.to_i}:00 AM"
20
+ elsif minute != "*" && hour != "*"
21
+ hour_val = hour.to_i
22
+ time_string = "At #{hour_val > 12 ? hour_val - 12 : hour_val}:#{minute.to_i.to_s.rjust(2, '0')} #{hour_val >= 12 ? 'PM' : 'AM'}"
23
+ elsif minute != "*" && hour == "*"
24
+ time_string = "At #{minute.to_i} minutes past the hour"
25
+ end
26
+
27
+ # For day string
28
+ if day_of_month != "*"
29
+ day_string = ", on day #{day_of_month} of the month"
30
+ elsif day_of_week =~ /\d#(\d)/
31
+ week_num = $1
32
+ day_num = day_of_week[0].to_i
33
+ day_string = ", on the #{week_num.ordinalize} #{days_of_week[day_num]} of the month"
34
+ elsif day_of_week != "*"
35
+ day_num = day_of_week.to_i
36
+ day_string = ", only on #{days_of_week[day_num]}"
37
+ end
38
+
39
+ # For month string
40
+ if month != "*" && month != "*/1"
41
+ month_string = ", every #{month.gsub('*/','')} months"
42
+ end
43
+
44
+ return "#{time_string}#{day_string}#{month_string}"
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ module CronDescriber
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cron_describer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksander Lopez Yazikov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: A Ruby gem that takes a cron schedule string and converts it into a human-readable
28
+ time description.
29
+ email:
30
+ - webodessa@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rspec"
36
+ - CHANGELOG.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - cron_describer.gemspec
41
+ - lib/cron_describer.rb
42
+ - lib/cron_describer/version.rb
43
+ - sig/cron_describer.rbs
44
+ homepage: https://github.com/logicalgroove/cron_describer
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ homepage_uri: https://github.com/logicalgroove/cron_describer
49
+ source_code_uri: https://github.com/logicalgroove/cron_describer
50
+ changelog_uri: https://github.com/logicalgroove/cron_describer
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.6.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.2.32
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: A gem to convert cron schedule strings into human-readable time
70
+ test_files: []