goldman 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/Rakefile +18 -0
- data/exe/goldman +5 -2
- data/goldman.gemspec +1 -1
- data/lib/goldman/date_range.rb +73 -0
- data/lib/goldman/generator.rb +3 -3
- data/lib/goldman/version.rb +1 -1
- data/lib/goldman.rb +1 -1
- metadata +4 -4
- data/lib/goldman/date_form.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c43ad648ae8b70aa4fc9c685d49c4e4a51dfc5fcf8502568591a232f6456f58b
|
4
|
+
data.tar.gz: ed94b8ab0a2d8275e4dccba56a85f54e987afad71973086052727c545a92037f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67132dae664ff6501afddcdf2a04098b2e74bb7aabde76422e01b7df80e40d8f02685a7ecb862705f7b848df1e4a8d80f7c050ff87a0cd20623b3f54c2abb7f
|
7
|
+
data.tar.gz: b0cbf1313bef97ab2907743aed72b9e7113accf6c009ca21e46d3823cf67fee04a5ef7bad5a42bc16cf5d6b362cc316fee2e10f0815aac4d8f2d44845048966c
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -14,3 +14,21 @@ require "rubocop/rake_task"
|
|
14
14
|
RuboCop::RakeTask.new
|
15
15
|
|
16
16
|
task default: %i[test rubocop]
|
17
|
+
|
18
|
+
namespace "gem" do
|
19
|
+
desc "Build a gem package"
|
20
|
+
task :build do
|
21
|
+
sh "gem build goldman.gemspec"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Push a gem package"
|
25
|
+
task :push do
|
26
|
+
Rake::Task["gem:build"].execute
|
27
|
+
sh "gem push goldman-#{Goldman::VERSION}.gem"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Clean built gem packages"
|
31
|
+
task :clean do
|
32
|
+
sh "rm goldman-*.gem"
|
33
|
+
end
|
34
|
+
end
|
data/exe/goldman
CHANGED
@@ -33,11 +33,14 @@ def error(message)
|
|
33
33
|
end
|
34
34
|
|
35
35
|
begin
|
36
|
-
|
36
|
+
date_list = Goldman::DateRange.new(start_date_str: @options[:start_date],
|
37
|
+
end_date_str: @options[:end_date],
|
38
|
+
day_str: @options[:day],
|
39
|
+
week_str: @options[:week]).date_list
|
37
40
|
config = Goldman::Config.new(@options[:config])
|
38
41
|
formatter = Goldman::Formatter.new(config)
|
39
42
|
data = Goldman::DataLoader.new(config).data
|
40
|
-
generator = Goldman::Generator.new(data, formatter,
|
43
|
+
generator = Goldman::Generator.new(data, formatter, date_list)
|
41
44
|
|
42
45
|
@options.each do |k, v|
|
43
46
|
case k
|
data/goldman.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = %q{goldman for generating option list of schedule}
|
13
13
|
spec.homepage = "https://github.com/willsmile/goldman-rb"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">=
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
16
|
|
17
17
|
# Specify which files should be added to the gem when it is released.
|
18
18
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Goldman
|
6
|
+
class DateRange
|
7
|
+
attr_reader :start_date, :end_date
|
8
|
+
|
9
|
+
def initialize(start_date_str:, end_date_str:, day_str:, week_str:)
|
10
|
+
@week = to_integer!(week_str, "week") || default_week
|
11
|
+
@day = to_integer!(day_str, "day") || default_day
|
12
|
+
@start_date = to_date!(start_date_str, "start_date") || default_start_date
|
13
|
+
@end_date = to_date!(end_date_str, "end_date") || calculate_end_date
|
14
|
+
validate!
|
15
|
+
end
|
16
|
+
|
17
|
+
def date_list
|
18
|
+
(@start_date..@end_date).to_a
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def calculate_end_date
|
24
|
+
if @week > 0
|
25
|
+
@start_date + @week * 7 - 1
|
26
|
+
elsif @day > 0
|
27
|
+
@start_date + @day - 1
|
28
|
+
else
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate!
|
34
|
+
end_date_err_msg = "The parameter of week (#{@week}) or day (#{@day}) is invalid."
|
35
|
+
raise Goldman::ParameterError.new(end_date_err_msg) if @end_date.nil?
|
36
|
+
|
37
|
+
date_range_err_msg = "The start_date (#{@start_date}) should be before end_date (#{@end_date})."
|
38
|
+
raise Goldman::ParameterError.new(date_range_err_msg) if @start_date > @end_date
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_date!(str, source)
|
42
|
+
return if str.nil?
|
43
|
+
|
44
|
+
begin
|
45
|
+
Date.parse(str)
|
46
|
+
rescue Date::Error, TypeError
|
47
|
+
raise Goldman::ParameterError.new("The parameter of #{source} (#{str}) is invalid.")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_integer!(str, source)
|
52
|
+
return if str.nil?
|
53
|
+
|
54
|
+
begin
|
55
|
+
Integer(str)
|
56
|
+
rescue ArgumentError, TypeError
|
57
|
+
raise Goldman::ParameterError.new("The parameter of #{source} (#{str}) is invalid.")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_start_date
|
62
|
+
Date.today
|
63
|
+
end
|
64
|
+
|
65
|
+
def default_week
|
66
|
+
0
|
67
|
+
end
|
68
|
+
|
69
|
+
def default_day
|
70
|
+
7
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/goldman/generator.rb
CHANGED
@@ -4,16 +4,16 @@ require "date"
|
|
4
4
|
|
5
5
|
module Goldman
|
6
6
|
class Generator
|
7
|
-
def initialize(data, formatter,
|
7
|
+
def initialize(data, formatter, date_list)
|
8
8
|
@data = data
|
9
9
|
@formatter = formatter
|
10
|
-
@
|
10
|
+
@date_list = date_list
|
11
11
|
end
|
12
12
|
|
13
13
|
def exec
|
14
14
|
raise Goldman::OperationError.new("No data for schedule. Please define them in the config file.") if @data.empty?
|
15
15
|
|
16
|
-
@
|
16
|
+
@date_list.each do |date|
|
17
17
|
@data[date.cwday]&.each do |time|
|
18
18
|
@formatter.schedule(date, time)
|
19
19
|
end
|
data/lib/goldman/version.rb
CHANGED
data/lib/goldman.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "goldman/config"
|
4
4
|
require_relative "goldman/data_loader"
|
5
|
-
require_relative "goldman/
|
5
|
+
require_relative "goldman/date_range"
|
6
6
|
require_relative "goldman/formatter"
|
7
7
|
require_relative "goldman/generator"
|
8
8
|
require_relative "goldman/version"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goldman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wei Chen (willsmile)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: goldman for generating option list of schedule
|
14
14
|
email:
|
@@ -29,7 +29,7 @@ files:
|
|
29
29
|
- lib/goldman.rb
|
30
30
|
- lib/goldman/config.rb
|
31
31
|
- lib/goldman/data_loader.rb
|
32
|
-
- lib/goldman/
|
32
|
+
- lib/goldman/date_range.rb
|
33
33
|
- lib/goldman/formatter.rb
|
34
34
|
- lib/goldman/generator.rb
|
35
35
|
- lib/goldman/version.rb
|
@@ -46,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 3.0.0
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
data/lib/goldman/date_form.rb
DELETED
@@ -1,64 +0,0 @@
|
|
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
|