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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c43ad648ae8b70aa4fc9c685d49c4e4a51dfc5fcf8502568591a232f6456f58b
4
- data.tar.gz: ed94b8ab0a2d8275e4dccba56a85f54e987afad71973086052727c545a92037f
3
+ metadata.gz: 8f773ac07453545627e3f47a174af08c8260d8e0146861adeea9808bc7d174ea
4
+ data.tar.gz: 788b04e2dba00c069d331ae648841b4ffd156b70639d4773a2cca000014625df
5
5
  SHA512:
6
- metadata.gz: a67132dae664ff6501afddcdf2a04098b2e74bb7aabde76422e01b7df80e40d8f02685a7ecb862705f7b848df1e4a8d80f7c050ff87a0cd20623b3f54c2abb7f
7
- data.tar.gz: b0cbf1313bef97ab2907743aed72b9e7113accf6c009ca21e46d3823cf67fee04a5ef7bad5a42bc16cf5d6b362cc316fee2e10f0815aac4d8f2d44845048966c
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
- 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
40
- config = Goldman::Config.new(@options[:config])
41
- formatter = Goldman::Formatter.new(config)
42
- data = Goldman::DataLoader.new(config).data
43
- generator = Goldman::Generator.new(data, formatter, date_list)
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
- generator.exec
54
+ presenter.exec
49
55
  when *NON_OPERATIONAL_OPTS
50
56
  # Do nothing here
51
57
  when :version
@@ -4,13 +4,13 @@ require "psych"
4
4
 
5
5
  module Goldman
6
6
  class Config
7
- attr_reader :raw_data, :customized_format
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
- @raw_data = load_data
13
- @customized_format = load_customized_format
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 load_customized_format
28
+ def load_format
29
29
  return {} unless @config.has_key?(:format)
30
30
 
31
31
  @config[:format]
@@ -14,10 +14,12 @@ module Goldman
14
14
  validate!
15
15
  end
16
16
 
17
- def date_list
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
- 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
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)
@@ -4,9 +4,9 @@ module Goldman
4
4
  class Formatter
5
5
  attr_reader :customized_format, :default_format
6
6
 
7
- def initialize(config)
8
- @customized_format = config.customized_format
9
- @default_format = 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 DataLoader
5
- def initialize(config)
6
- @raw_data = config.raw_data
4
+ class Schedule
5
+
6
+ def initialize(data:)
7
+ @data = data
7
8
  end
8
9
 
9
- def data
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
- @raw_data[name]
29
+ @data[name]
31
30
  end
32
31
 
33
32
  def weekday
34
- @raw_data[:Weekday]
33
+ @data[:Weekday]
35
34
  end
36
35
 
37
36
  def weekend
38
- @raw_data[:Weekend]
37
+ @data[:Weekend]
39
38
  end
40
39
 
41
40
  def everyday
42
- @raw_data[:Everyday]
41
+ @data[:Everyday]
43
42
  end
44
43
  end
45
44
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Goldman
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
 
6
6
  def self.version
7
7
  puts "Goldman version #{VERSION}"
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/generator"
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.3
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-12 00:00:00.000000000 Z
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/generator.rb
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
@@ -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