goldman 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +56 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +16 -0
- data/exe/goldman +57 -0
- data/goldman.gemspec +33 -0
- data/lib/goldman/config.rb +34 -0
- data/lib/goldman/data_loader.rb +45 -0
- data/lib/goldman/date_form.rb +64 -0
- data/lib/goldman/formatter.rb +34 -0
- data/lib/goldman/generator.rb +23 -0
- data/lib/goldman/version.rb +9 -0
- data/lib/goldman/wday.rb +37 -0
- data/lib/goldman.rb +30 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 94e9f4694277445b718dc5efec92c4b621540ac8800802980c795e6fb2998060
|
4
|
+
data.tar.gz: cf7dc5372d1f68547e08ebe11dd3216e304e933a29e3e84d4ef338c40bfbbca5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1a511821fe32070639b8213704db0d5c1f515b9b65f88bfbfa1086a79a92ec0fb88254b83575a4f6383784677f8c4d401ca5ceb63307d94e0c9e493b02da429
|
7
|
+
data.tar.gz: 5e4bc508cb884737b0c87322513c53c16ebeee262da65050d1c36afe8e1baddcb3651511a10502343c785b99e3886d6880d0dc9fb29c9461874e13e48c0b6f0b
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
DisabledByDefault: true
|
4
|
+
SuggestExtensions: false
|
5
|
+
Exclude:
|
6
|
+
- goldman.gemspec
|
7
|
+
- bin/*
|
8
|
+
- vendor/**/*
|
9
|
+
|
10
|
+
Style/HashSyntax:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Style/StringLiterals:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: double_quotes
|
16
|
+
|
17
|
+
Style/MultilineIfThen:
|
18
|
+
Enabled: true
|
19
|
+
|
20
|
+
Style/MethodDefParentheses:
|
21
|
+
Enabled: true
|
22
|
+
|
23
|
+
Layout/LineLength:
|
24
|
+
Enabled: true
|
25
|
+
Max: 120
|
26
|
+
|
27
|
+
Layout/IndentationWidth:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Layout/IndentationStyle:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Layout/EmptyLines:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Layout/TrailingEmptyLines:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Layout/TrailingWhitespace:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Layout/SpaceBeforeBlockBraces:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Layout/SpaceInsideBlockBraces:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Layout/SpaceInsideHashLiteralBraces:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Layout/CaseIndentation:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Layout/EndAlignment:
|
55
|
+
Enabled: true
|
56
|
+
EnforcedStyleAlignWith: variable
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at smile.v.chen@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Wei Chen
|
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,82 @@
|
|
1
|
+
# Goldman
|
2
|
+
|
3
|
+
Goldman is a tool for [g]enerating [o]ption [l]ist of sche[d]ule. And goldman-rb is its ruby
|
4
|
+
implementation.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Goldman's installation is standard for a Ruby gem:
|
9
|
+
|
10
|
+
```sh
|
11
|
+
gem install goldman
|
12
|
+
```
|
13
|
+
|
14
|
+
## Setup and configuration
|
15
|
+
Please create a configuration file `config.yml` in the path `~/.goldman`. If you want to change the config path, please use the environment variable `GOLDMANPATH.`
|
16
|
+
|
17
|
+
Please define the data of schedule options are described in `config.yml` as follows.
|
18
|
+
The available data keys are `everyday`, `weekday`, `weekend`, and the day of the week.
|
19
|
+
|
20
|
+
```yml:config.yml
|
21
|
+
data:
|
22
|
+
everyday:
|
23
|
+
- "10:00~11:00"
|
24
|
+
weekday:
|
25
|
+
- "12:00~13:00"
|
26
|
+
weekend:
|
27
|
+
- "20:00~21:00"
|
28
|
+
monday:
|
29
|
+
- "16:00~17:00"
|
30
|
+
wednesday:
|
31
|
+
- "16:00~17:00"
|
32
|
+
thursday:
|
33
|
+
- "16:00~17:00"
|
34
|
+
```
|
35
|
+
|
36
|
+
You can customize the format to display each schedule option by setting them up in `config.yml`. If it is not customized, the tool uses the default one.
|
37
|
+
|
38
|
+
```yml:config.yml
|
39
|
+
format:
|
40
|
+
schedule: "%{date}(%{wday}) %{time}"
|
41
|
+
date: "%Y/%m/%d"
|
42
|
+
wday:
|
43
|
+
monday: "月"
|
44
|
+
tuesday: "火"
|
45
|
+
wednesday: "水"
|
46
|
+
thursday: "木"
|
47
|
+
friday: "金"
|
48
|
+
saturday: "土"
|
49
|
+
sunday: "日"
|
50
|
+
```
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
The start date will always be today if it is not specified.
|
54
|
+
|
55
|
+
```sh
|
56
|
+
# Generate schedule options in a week
|
57
|
+
goldman -g
|
58
|
+
|
59
|
+
# Generate schedule options starting from today (assume 2023-04-25) and ending to 2023-04-30
|
60
|
+
goldman -g -e 2023-04-30
|
61
|
+
|
62
|
+
# Generate schedule options starting from 2023-05-08 and ending to 2023-04-30
|
63
|
+
goldman -g -s 2023-05-08 -e 2023-05-12
|
64
|
+
|
65
|
+
# Generate schedule options in three weeks
|
66
|
+
goldman -g -w 3
|
67
|
+
|
68
|
+
# Generate schedule options in eight days
|
69
|
+
goldman -g -d 8
|
70
|
+
```
|
71
|
+
|
72
|
+
The example of generated schedule options is as follows.
|
73
|
+
|
74
|
+
```sh
|
75
|
+
❯ goldman -g -d 5
|
76
|
+
2023/04/25(Tue) 12:00~13:00
|
77
|
+
2023/04/26(Wed) 12:00~13:00
|
78
|
+
2023/04/26(Wed) 16:00~17:00
|
79
|
+
2023/04/27(Thu) 12:00~13:00
|
80
|
+
2023/04/27(Thu) 16:00~17:00
|
81
|
+
2023/04/28(Fri) 12:00~13:00
|
82
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
data/exe/goldman
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# (C) Wei Chen (willsmile)
|
5
|
+
# MIT license
|
6
|
+
|
7
|
+
require "goldman"
|
8
|
+
require "optparse"
|
9
|
+
|
10
|
+
GOLDMANPATH = ENV["GOLDMANPATH"] || File.expand_path("~/.goldman")
|
11
|
+
CONFIG_FILENAME = "config.yml"
|
12
|
+
NON_OPERATIONAL_OPTS = [:config]
|
13
|
+
|
14
|
+
# default value
|
15
|
+
@options = {
|
16
|
+
config: GOLDMANPATH + "/" + CONFIG_FILENAME
|
17
|
+
}
|
18
|
+
|
19
|
+
opts = OptionParser.new do |opts|
|
20
|
+
opts.on("-c", "--config FILE", "Use a config file") { |v| @options[:config] = v }
|
21
|
+
opts.on("-g", "--generate", "Generate list of schedule options") { |v| @options[:generate] = v }
|
22
|
+
opts.on("-s", "--start [DATE]", "Set start date") { |v| @options[:start_date] = v }
|
23
|
+
opts.on("-e", "--end [DATE]", "Set end date") { |v| @options[:end_date] = v }
|
24
|
+
opts.on("-d", "--day [INTEGER]", "Set day interval from start date") { |v| @options[:day] = v }
|
25
|
+
opts.on("-w", "--week [INTEGER]", "Set week interval from start date") { |v| @options[:week] = v }
|
26
|
+
opts.on("-v", "--version", "Show tool version") { |v| @options[:version] = v }
|
27
|
+
|
28
|
+
opts.parse!(ARGV)
|
29
|
+
end
|
30
|
+
|
31
|
+
def error(message)
|
32
|
+
warn "ERROR: #{message}"
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
date_form = Goldman::DateForm.new(@options)
|
38
|
+
config = Goldman::Config.new(@options[:config])
|
39
|
+
formatter = Goldman::Formatter.new(config)
|
40
|
+
data = Goldman::DataLoader.new(config).data
|
41
|
+
generator = Goldman::Generator.new(data, formatter, date_form)
|
42
|
+
|
43
|
+
@options.each do |k, v|
|
44
|
+
case k
|
45
|
+
when :generate
|
46
|
+
generator.exec
|
47
|
+
when *NON_OPERATIONAL_OPTS
|
48
|
+
# Do nothing here
|
49
|
+
when :version
|
50
|
+
Goldman.version
|
51
|
+
end
|
52
|
+
end
|
53
|
+
rescue Goldman::Error => ex
|
54
|
+
error ex.message
|
55
|
+
rescue Errno::ENOENT
|
56
|
+
error "Config file (#{@options[:config]}) dose not exist."
|
57
|
+
end
|
data/goldman.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/goldman/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "goldman"
|
7
|
+
spec.version = Goldman::VERSION
|
8
|
+
spec.authors = ["Wei Chen (willsmile)"]
|
9
|
+
spec.email = ["willsmile.me@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{goldman}
|
12
|
+
spec.description = %q{goldman for generating option list of schedule}
|
13
|
+
spec.homepage = "https://github.com/willsmile/goldman-rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(__dir__) do
|
20
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
# Uncomment to register a new dependency of your gem
|
29
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
30
|
+
|
31
|
+
# For more information and examples about making a new gem, check out our
|
32
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "psych"
|
4
|
+
|
5
|
+
module Goldman
|
6
|
+
class Config
|
7
|
+
attr_reader :raw_data, :customized_format
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
@config = load_file
|
12
|
+
@raw_data = load_data
|
13
|
+
@customized_format = load_customized_format
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def load_file
|
19
|
+
Psych.safe_load_file(@path, symbolize_names: true)
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_data
|
23
|
+
return {} unless @config.has_key?(:data)
|
24
|
+
|
25
|
+
@config[:data]
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_customized_format
|
29
|
+
return {} unless @config.has_key?(:format)
|
30
|
+
|
31
|
+
@config[:format]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldman
|
4
|
+
class DataLoader
|
5
|
+
def initialize(config)
|
6
|
+
@raw_data = config.raw_data
|
7
|
+
end
|
8
|
+
|
9
|
+
def data
|
10
|
+
result = {}
|
11
|
+
Goldman::Wday.members.each do |w|
|
12
|
+
periods = []
|
13
|
+
periods += wday(w) unless wday(w).nil?
|
14
|
+
periods += everyday unless everyday.nil?
|
15
|
+
periods += weekday if Goldman::Wday.weekday?(w) && !weekday.nil?
|
16
|
+
periods += weekend if Goldman::Wday.weekend?(w) && !weekend.nil?
|
17
|
+
result[Goldman::Wday.to_num(w)] = sort(periods) unless periods.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def sort(periods)
|
26
|
+
periods.sort_by { _1.split(":").first.to_i }
|
27
|
+
end
|
28
|
+
|
29
|
+
def wday(name)
|
30
|
+
@raw_data[name]
|
31
|
+
end
|
32
|
+
|
33
|
+
def weekday
|
34
|
+
@raw_data[:weekday]
|
35
|
+
end
|
36
|
+
|
37
|
+
def weekend
|
38
|
+
@raw_data[:weekend]
|
39
|
+
end
|
40
|
+
|
41
|
+
def everyday
|
42
|
+
@raw_data[:everyday]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Goldman
|
6
|
+
class DateForm
|
7
|
+
def initialize(options)
|
8
|
+
@week_num = parse_num!(options[:week], "week")
|
9
|
+
@day_num = parse_num!(options[:day], "day") || default_day_num
|
10
|
+
@start_date = parse_date!(options[:start_date], "start_date") || today
|
11
|
+
@end_date = parse_date!(options[:end_date], "end_date")
|
12
|
+
validate_end_date!
|
13
|
+
end
|
14
|
+
|
15
|
+
def range
|
16
|
+
return @start_date..@end_date if @end_date
|
17
|
+
|
18
|
+
@start_date..(@start_date + interval_day)
|
19
|
+
end
|
20
|
+
|
21
|
+
def interval_day
|
22
|
+
return @week_num * 7 - 1 if @week_num
|
23
|
+
|
24
|
+
@day_num - 1
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def validate_end_date!
|
30
|
+
return if @end_date.nil?
|
31
|
+
|
32
|
+
err_msg = "The date in start_date (#{@start_date}) should be before the date in end_date (#{@end_date})."
|
33
|
+
raise Goldman::ParameterError.new(err_msg) if @start_date > @end_date
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_date!(str, source)
|
37
|
+
return if str.nil?
|
38
|
+
|
39
|
+
begin
|
40
|
+
Date.parse(str)
|
41
|
+
rescue Date::Error, TypeError
|
42
|
+
raise Goldman::ParameterError.new("The parameter of #{source} (#{str}) is invalid.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_num!(str, source)
|
47
|
+
return if str.nil?
|
48
|
+
|
49
|
+
begin
|
50
|
+
Integer(str)
|
51
|
+
rescue ArgumentError, TypeError
|
52
|
+
raise Goldman::ParameterError.new("The parameter of #{source} (#{str}) is invalid.")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def today
|
57
|
+
Date.today
|
58
|
+
end
|
59
|
+
|
60
|
+
def default_day_num
|
61
|
+
7
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldman
|
4
|
+
class Formatter
|
5
|
+
attr_reader :customized_format, :default_format
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@customized_format = config.customized_format
|
9
|
+
@default_format = DEFAULT_FORMAT
|
10
|
+
end
|
11
|
+
|
12
|
+
def schedule(date, time_str)
|
13
|
+
puts format(:schedule) % { date: formatted_date(date), wday: formatted_wday(date.cwday), time: time_str }
|
14
|
+
end
|
15
|
+
|
16
|
+
def format(target)
|
17
|
+
return @customized_format[target] if @customized_format&.has_key?(target)
|
18
|
+
|
19
|
+
@default_format[target]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def formatted_wday(wday_num)
|
25
|
+
wday_name = Goldman::Wday.to_name(wday_num)
|
26
|
+
format(:wday)[wday_name]
|
27
|
+
end
|
28
|
+
|
29
|
+
def formatted_date(date)
|
30
|
+
format = format(:date)
|
31
|
+
date.strftime(format)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Goldman
|
6
|
+
class Generator
|
7
|
+
def initialize(data, formatter, date_form)
|
8
|
+
@data = data
|
9
|
+
@formatter = formatter
|
10
|
+
@date_form = date_form
|
11
|
+
end
|
12
|
+
|
13
|
+
def exec
|
14
|
+
raise Goldman::OperationError.new("No data for schedule. Please define them in the config file.") if @data.empty?
|
15
|
+
|
16
|
+
@date_form.range.each do |date|
|
17
|
+
@data[date.cwday]&.each do |time|
|
18
|
+
@formatter.schedule(date, time)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/goldman/wday.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Goldman
|
4
|
+
module Wday
|
5
|
+
DATA = {
|
6
|
+
monday: 1,
|
7
|
+
tuesday: 2,
|
8
|
+
wednesday: 3,
|
9
|
+
thursday: 4,
|
10
|
+
friday: 5,
|
11
|
+
saturday: 6,
|
12
|
+
sunday: 7
|
13
|
+
}
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def members
|
17
|
+
DATA.keys
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_name(num)
|
21
|
+
DATA.key(num)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_num(name)
|
25
|
+
DATA[name]
|
26
|
+
end
|
27
|
+
|
28
|
+
def weekday?(name)
|
29
|
+
DATA[name] < 6
|
30
|
+
end
|
31
|
+
|
32
|
+
def weekend?(name)
|
33
|
+
DATA[name] > 5
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/goldman.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "goldman/config"
|
4
|
+
require_relative "goldman/data_loader"
|
5
|
+
require_relative "goldman/date_form"
|
6
|
+
require_relative "goldman/formatter"
|
7
|
+
require_relative "goldman/generator"
|
8
|
+
require_relative "goldman/version"
|
9
|
+
require_relative "goldman/wday"
|
10
|
+
|
11
|
+
module Goldman
|
12
|
+
DEFAULT_FORMAT = {
|
13
|
+
schedule: "%{date}(%{wday}) %{time}",
|
14
|
+
date: "%Y/%m/%d",
|
15
|
+
wday: {
|
16
|
+
monday: "Mon",
|
17
|
+
tuesday: "Tue",
|
18
|
+
wednesday: "Wed",
|
19
|
+
thursday: "Thu",
|
20
|
+
friday: "Fri",
|
21
|
+
saturday: "Sat",
|
22
|
+
sunday: "Sun"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
class Error < StandardError; end
|
27
|
+
class ParameterError < Error; end
|
28
|
+
class ConfigurationError < Error; end
|
29
|
+
class OperationError < Error; end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goldman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wei Chen (willsmile)
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: goldman for generating option list of schedule
|
14
|
+
email:
|
15
|
+
- willsmile.me@gmail.com
|
16
|
+
executables:
|
17
|
+
- goldman
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- exe/goldman
|
28
|
+
- goldman.gemspec
|
29
|
+
- lib/goldman.rb
|
30
|
+
- lib/goldman/config.rb
|
31
|
+
- lib/goldman/data_loader.rb
|
32
|
+
- lib/goldman/date_form.rb
|
33
|
+
- lib/goldman/formatter.rb
|
34
|
+
- lib/goldman/generator.rb
|
35
|
+
- lib/goldman/version.rb
|
36
|
+
- lib/goldman/wday.rb
|
37
|
+
homepage: https://github.com/willsmile/goldman-rb
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.7.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.4.10
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: goldman
|
60
|
+
test_files: []
|