payment_day 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +2 -2
- data/README.md +35 -12
- data/lib/payment_day/cli.rb +12 -1
- data/lib/payment_day/version.rb +1 -1
- data/lib/payment_day.rb +35 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a279d6517217a079c005e643cf8ed2800d5738c870f46143debd39d30a6cf8d1
|
4
|
+
data.tar.gz: dcf679700489acc4548e0c008f6a23cd61d08bfa9bc934bcb16ca16c81c04142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465d44ca851085f3bfc56ffdd14eb877a56baa625abad29fb8787d5c94bf5eab8e579a9595ff6538afe01baa50f9c091cf962c7e675751dadc73f1e72eca8ca5
|
7
|
+
data.tar.gz: f113f82e0799a51150959e007bd64db74e78fb2d243487414cd8bc1d5ecc37301c145e5c42ecebe9b4514b19b9797a4a6535a4fe3cb136e97dc2a91acf249f2a
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
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
|
-
|
25
|
+
payment_day!
|
26
26
|
rake (~> 13.0)
|
27
27
|
|
28
28
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# PaymentDay
|
2
2
|
|
3
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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/
|
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
|
|
data/lib/payment_day/cli.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/payment_day/version.rb
CHANGED
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
|
-
|
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
|
-
@
|
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 =
|
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
|
-
@
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2022-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|