payment_day 0.1.1 → 0.1.2

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: f831e07338ecf125bda97e4c77b9f0968c4cb4c60625addfecb5bedbfd906c4c
4
- data.tar.gz: 41200c85a4bce203446ab8a66936eeb0fa39609acbad4cb703d3432a646a526d
3
+ metadata.gz: a279d6517217a079c005e643cf8ed2800d5738c870f46143debd39d30a6cf8d1
4
+ data.tar.gz: dcf679700489acc4548e0c008f6a23cd61d08bfa9bc934bcb16ca16c81c04142
5
5
  SHA512:
6
- metadata.gz: f72f3c88895c8a5e38a5811af9ba180172833412c739e000f68d8586e338bc9a8e25232dccebe2723edeeb432694da3ed291e29834892342923d8a0d3541cba3
7
- data.tar.gz: d0fbf52275d7298466fbbc11343ddecec8f95c637769f623a746a704d50aea634e623a1a760d92d65887fe554ba012ee6db5026915e8fb2c8426e40d574fd9da
6
+ metadata.gz: 465d44ca851085f3bfc56ffdd14eb877a56baa625abad29fb8787d5c94bf5eab8e579a9595ff6538afe01baa50f9c091cf962c7e675751dadc73f1e72eca8ca5
7
+ data.tar.gz: f113f82e0799a51150959e007bd64db74e78fb2d243487414cd8bc1d5ecc37301c145e5c42ecebe9b4514b19b9797a4a6535a4fe3cb136e97dc2a91acf249f2a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.12] - 2022-12-31
4
+
5
+ - Refactoring
6
+ - pay_day executable supports more options
7
+
8
+ ## [0.1.11] - 2022-12-28
9
+
10
+ - Refactoring
11
+
3
12
  ## [0.1.0] - 2022-12-27
4
13
 
5
14
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pay_day (0.1.0)
4
+ payment_day (0.1.1)
5
5
  rainbow (~> 3.1)
6
6
  terminal-table (~> 3.0)
7
7
  thor (~> 1.2)
@@ -22,7 +22,7 @@ PLATFORMS
22
22
 
23
23
  DEPENDENCIES
24
24
  minitest (~> 5.0)
25
- pay_day!
25
+ payment_day!
26
26
  rake (~> 13.0)
27
27
 
28
28
  BUNDLED WITH
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # PayDay
1
+ # PaymentDay
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pay_day`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Provides a class PaymentDay::View. This class generates the pay days for the given year(s).
6
4
 
7
5
  ## Installation
8
6
 
@@ -16,17 +14,42 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
14
 
17
15
  ## Usage
18
16
 
19
- TODO: Write usage instructions here
20
-
21
- ## Development
22
-
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
-
25
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
17
+ ```ruby
18
+ # Get the pay days
19
+ PaymentDay::View(2023).pay_days # return Array of Hash(es) with the pay_days
20
+ PaymentDay::View("2023").pay_days # accept String as input
21
+ PaymentDay::View(2023, 2024).pay_days # accept multiple years
22
+ PaymentDay::View([2023]).pay_days # accept Array's as input
23
+ PaymentDay::View("2023-2024").pay_days # accept String ranges
24
+ PaymentDay::View(2023..2024).pay_days # accept Range as input
25
+ PaymentDay::View(2023..2024, 2025, '2026').pay_days # accept a mix of all of them
26
+
27
+ # Last parameter defines the options if set
28
+ # shows 2023 twice in the list of pay_days, default is false
29
+ PaymentDay::View(2023..2024, 2023, duplicates: true).pay_days
30
+
31
+ table = PaymentDay::View(2023).list # returns a Terminal::Table instance
32
+ puts table # which can be printed like this
33
+ ```
34
+
35
+ ### payment_day executable supports the following options:
36
+
37
+ Option | Negated | Shortcut | Default
38
+ --- | ---: | ---: | ---:
39
+ --ascii | --no-ascii | (-a) | [default: false]
40
+ --columns | | (-c) | [default: 10]
41
+ --dayname | --no-dayname | (-n) | [default: true]
42
+ --duplicates | --no-duplicates | (-d) | [default: false]
43
+ --footer | --no-footer | (-f) | [default: true]
44
+ --separator | --no-separator | (-s) | [default: true]
45
+
46
+ ```bash
47
+ payment_day list 2023 2024 2025-2027
48
+ ```
26
49
 
27
50
  ## Contributing
28
51
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pay_day.
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/the-pulli/payment_day.
30
53
 
31
54
  ## License
32
55
 
@@ -8,9 +8,20 @@ module PaymentDay
8
8
  class CLI < Thor
9
9
  desc "list", "Lists all pay days for the given year(s)"
10
10
  method_option :ascii, aliases: "-a", type: :boolean, default: false
11
+ method_option :columns, aliases: "-c", type: :numeric, default: 10
12
+ method_option :dayname, aliases: "-n", type: :boolean, default: true
13
+ method_option :duplicates, aliases: "-d", type: :boolean, default: false
14
+ method_option :footer, aliases: "-f", type: :boolean, default: true
11
15
  method_option :separator, aliases: "-s", type: :boolean, default: true
12
16
  def list(*years)
13
- puts PaymentDay::View.new(years, options).list
17
+ years = PaymentDay::View.new(years, options).years
18
+ years = years.each_slice(options[:columns])
19
+ years.each_with_index do |yearsChunk, page|
20
+ year_options = options.dup
21
+ year_options[:page] = page.next
22
+ year_options[:pages] = years.to_a.length
23
+ puts PaymentDay::View.new(yearsChunk, year_options).list()
24
+ end
14
25
  end
15
26
  end
16
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaymentDay
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/payment_day.rb CHANGED
@@ -8,24 +8,30 @@ require_relative "payment_day/version"
8
8
  module PaymentDay
9
9
  # View class
10
10
  class View
11
- MONTHS = %w[January February March April May June July August September October November December].freeze
12
-
13
- attr_reader :pay_days
11
+ attr_reader :pay_days, :years
14
12
 
15
13
  def initialize(*years)
14
+ default_options = { separator: true, ascii: false, dayname: false, page: nil, pages: nil, duplicates: false, footer: true }
16
15
  options = years.last.is_a?(Hash) ? years.slice!(-1) : {}
17
- @years = Array(prepare_years(years))
16
+ @months = []
17
+ @options = default_options.merge options.transform_keys(&:to_sym)
18
+ @years = prepare_years(years)
18
19
  @pay_days = find_pay_days
19
- @options = { separator: true, ascii: false }.merge options.transform_keys(&:to_sym)
20
20
  end
21
21
 
22
22
  def list
23
23
  Terminal::Table.new do |t|
24
24
  t.title = Rainbow("Pay days").bright
25
- t.headings = [Rainbow("Month").bright] + @years.map { |y| Rainbow(y).bright }
25
+ t.headings = [Rainbow("Month").bright] + @years.map { |y| { value: Rainbow(y).bright, alignment: :center } }
26
26
  t.style = { all_separators: @options[:separator], border: border }
27
- t.rows = MONTHS.map { |m| Rainbow(m).cyan }.zip(*format_pay_days)
27
+ t.rows = @months.map { |m| Rainbow(m).cyan }.zip(*format_pay_days)
28
28
  @years.each_index { |v| t.align_column v.next, :center }
29
+ page = @options[:page]
30
+ pages = @options[:pages]
31
+ unless !@options[:footer] || (page.nil? || (page == 1 && pages == 1))
32
+ t.add_row [{ colspan: @years.length.next, value: "Page #{page}/#{pages}",
33
+ alignment: :center }]
34
+ end
29
35
  end
30
36
  end
31
37
 
@@ -34,7 +40,7 @@ module PaymentDay
34
40
  private
35
41
 
36
42
  def prepare_years(years)
37
- years.flatten.map do |year|
43
+ result = years.flatten.map do |year|
38
44
  case year
39
45
  when Range
40
46
  year.to_a
@@ -49,19 +55,38 @@ module PaymentDay
49
55
  year
50
56
  end
51
57
  end.flatten
58
+
59
+ result = result.uniq unless @options[:duplicates]
60
+ Array(result)
52
61
  end
53
62
 
54
63
  def find_pay_days
55
- @years.map do |year|
64
+ unless @options[:duplicates]
65
+ year_hsh = {}
66
+ @years.each.with_index do |year, index|
67
+ year_hsh[year] = (1..12).to_a.map do |month|
68
+ last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
69
+ @months.push(last_day.strftime("%B")) if index.zero?
70
+ prev(last_day)
71
+ end
72
+ end
73
+ return year_hsh
74
+ end
75
+
76
+ @years.map.with_index do |year, index|
56
77
  (1..12).to_a.map do |month|
57
78
  last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
79
+ @months.push(last_day.strftime("%B")) if index.zero?
58
80
  prev(last_day)
59
81
  end
60
82
  end
61
83
  end
62
84
 
63
85
  def format_pay_days
64
- @pay_days.map { |year| year.map { |d| Rainbow(d.strftime("%d")).green } }
86
+ format = @options[:dayname] ? "%a, %d" : "%d"
87
+ return @pay_days.map { |_, year| year.map { |d| Rainbow(d.strftime(format)).green } } unless @options[:duplicates]
88
+
89
+ @pay_days.map { |year| year.map { |d| Rainbow(d.strftime(format)).green } }
65
90
  end
66
91
 
67
92
  def prev(day)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payment_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - PuLLi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-27 00:00:00.000000000 Z
11
+ date: 2022-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow