goldman 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/goldman +15 -9
- data/lib/goldman/config.rb +5 -5
- data/lib/goldman/date_range.rb +10 -6
- data/lib/goldman/formatter.rb +3 -3
- data/lib/goldman/presenter.rb +24 -0
- data/lib/goldman/{data_loader.rb → schedule.rb} +9 -10
- data/lib/goldman/version.rb +1 -1
- data/lib/goldman.rb +2 -2
- metadata +4 -4
- data/lib/goldman/generator.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f773ac07453545627e3f47a174af08c8260d8e0146861adeea9808bc7d174ea
|
4
|
+
data.tar.gz: 788b04e2dba00c069d331ae648841b4ffd156b70639d4773a2cca000014625df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c6bf7496046d91315c3344809ea010655d2078d9aa12932db6bb1f364b4c8d17e8b63ccccddf150f220fadc883e156160ad06f0f64b6e32f33310b97380d1b8
|
7
|
+
data.tar.gz: 3dae0f42687a4777fff508003d1f6d30055e1e22b71831787d19a110f45e198e1053a21aa0c2a790ac298ae279ac751752f4c5259f206eca5dc481be1715a46f
|
data/exe/goldman
CHANGED
@@ -33,19 +33,25 @@ def error(message)
|
|
33
33
|
end
|
34
34
|
|
35
35
|
begin
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
dates = Goldman::DateRange.new(
|
37
|
+
start_date_str: @options[:start_date],
|
38
|
+
end_date_str: @options[:end_date],
|
39
|
+
day_str: @options[:day],
|
40
|
+
week_str: @options[:week]
|
41
|
+
).to_a
|
42
|
+
config = Goldman::Config.new(path: @options[:config])
|
43
|
+
formatter = Goldman::Formatter.new(customized: config.format)
|
44
|
+
schedules = Goldman::Schedule.new(data: config.data).generate
|
45
|
+
presenter = Goldman::Presenter.new(
|
46
|
+
schedules: schedules,
|
47
|
+
formatter: formatter,
|
48
|
+
dates: dates
|
49
|
+
)
|
44
50
|
|
45
51
|
@options.each do |k, v|
|
46
52
|
case k
|
47
53
|
when :generate
|
48
|
-
|
54
|
+
presenter.exec
|
49
55
|
when *NON_OPERATIONAL_OPTS
|
50
56
|
# Do nothing here
|
51
57
|
when :version
|
data/lib/goldman/config.rb
CHANGED
@@ -4,13 +4,13 @@ require "psych"
|
|
4
4
|
|
5
5
|
module Goldman
|
6
6
|
class Config
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :data, :format
|
8
8
|
|
9
|
-
def initialize(path)
|
9
|
+
def initialize(path:)
|
10
10
|
@path = path
|
11
11
|
@config = load_file
|
12
|
-
@
|
13
|
-
@
|
12
|
+
@data = load_data
|
13
|
+
@format = load_format
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -25,7 +25,7 @@ module Goldman
|
|
25
25
|
@config[:data]
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def load_format
|
29
29
|
return {} unless @config.has_key?(:format)
|
30
30
|
|
31
31
|
@config[:format]
|
data/lib/goldman/date_range.rb
CHANGED
@@ -14,10 +14,12 @@ module Goldman
|
|
14
14
|
validate!
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def to_array
|
18
18
|
(@start_date..@end_date).to_a
|
19
19
|
end
|
20
20
|
|
21
|
+
alias_method :to_a, :to_array
|
22
|
+
|
21
23
|
private
|
22
24
|
|
23
25
|
def calculate_end_date
|
@@ -31,11 +33,13 @@ module Goldman
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def validate!
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if @end_date.nil?
|
37
|
+
end_date_err_msg = "The parameter of week (#{@week}) or day (#{@day}) is invalid."
|
38
|
+
raise Goldman::ParameterError.new(end_date_err_msg)
|
39
|
+
elsif @start_date > @end_date
|
40
|
+
date_range_err_msg = "The start_date (#{@start_date}) should be before end_date (#{@end_date})."
|
41
|
+
raise Goldman::ParameterError.new(date_range_err_msg)
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
def to_date!(str, source)
|
data/lib/goldman/formatter.rb
CHANGED
@@ -4,9 +4,9 @@ module Goldman
|
|
4
4
|
class Formatter
|
5
5
|
attr_reader :customized_format, :default_format
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@customized_format =
|
9
|
-
@default_format =
|
7
|
+
def initialize(customized:, default: DEFAULT_FORMAT)
|
8
|
+
@customized_format = customized
|
9
|
+
@default_format = default
|
10
10
|
end
|
11
11
|
|
12
12
|
def schedule(date, time_str)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Goldman
|
6
|
+
class Presenter
|
7
|
+
def initialize(schedules:, formatter:, dates:)
|
8
|
+
@schedules = schedules
|
9
|
+
@formatter = formatter
|
10
|
+
@dates = dates
|
11
|
+
end
|
12
|
+
|
13
|
+
def exec
|
14
|
+
raise Goldman::OperationError.new("No data for schedule. Please define them in the config file.") \
|
15
|
+
if @schedules.empty?
|
16
|
+
|
17
|
+
@dates.each do |date|
|
18
|
+
@schedules[date.cwday]&.each do |time|
|
19
|
+
@formatter.schedule(date, time)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Goldman
|
4
|
-
class
|
5
|
-
|
6
|
-
|
4
|
+
class Schedule
|
5
|
+
|
6
|
+
def initialize(data:)
|
7
|
+
@data = data
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
+
def generate
|
10
11
|
result = {}
|
11
12
|
Goldman::Wday.members.each do |w|
|
12
13
|
periods = []
|
@@ -20,26 +21,24 @@ module Goldman
|
|
20
21
|
result
|
21
22
|
end
|
22
23
|
|
23
|
-
private
|
24
|
-
|
25
24
|
def sort(periods)
|
26
25
|
periods.sort_by { _1.split(":").first.to_i }
|
27
26
|
end
|
28
27
|
|
29
28
|
def wday(name)
|
30
|
-
@
|
29
|
+
@data[name]
|
31
30
|
end
|
32
31
|
|
33
32
|
def weekday
|
34
|
-
@
|
33
|
+
@data[:Weekday]
|
35
34
|
end
|
36
35
|
|
37
36
|
def weekend
|
38
|
-
@
|
37
|
+
@data[:Weekend]
|
39
38
|
end
|
40
39
|
|
41
40
|
def everyday
|
42
|
-
@
|
41
|
+
@data[:Everyday]
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
data/lib/goldman/version.rb
CHANGED
data/lib/goldman.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "goldman/config"
|
4
|
-
require_relative "goldman/data_loader"
|
5
4
|
require_relative "goldman/date_range"
|
6
5
|
require_relative "goldman/formatter"
|
7
|
-
require_relative "goldman/
|
6
|
+
require_relative "goldman/presenter"
|
7
|
+
require_relative "goldman/schedule"
|
8
8
|
require_relative "goldman/version"
|
9
9
|
require_relative "goldman/wday"
|
10
10
|
|
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.4
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: goldman for generating option list of schedule
|
14
14
|
email:
|
@@ -28,10 +28,10 @@ files:
|
|
28
28
|
- goldman.gemspec
|
29
29
|
- lib/goldman.rb
|
30
30
|
- lib/goldman/config.rb
|
31
|
-
- lib/goldman/data_loader.rb
|
32
31
|
- lib/goldman/date_range.rb
|
33
32
|
- lib/goldman/formatter.rb
|
34
|
-
- lib/goldman/
|
33
|
+
- lib/goldman/presenter.rb
|
34
|
+
- lib/goldman/schedule.rb
|
35
35
|
- lib/goldman/version.rb
|
36
36
|
- lib/goldman/wday.rb
|
37
37
|
homepage: https://github.com/willsmile/goldman-rb
|
data/lib/goldman/generator.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "date"
|
4
|
-
|
5
|
-
module Goldman
|
6
|
-
class Generator
|
7
|
-
def initialize(data, formatter, date_list)
|
8
|
-
@data = data
|
9
|
-
@formatter = formatter
|
10
|
-
@date_list = date_list
|
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_list.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
|