payment_day 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +2 -2
- data/README.md +36 -12
- data/lib/payment_day/cli.rb +21 -5
- data/lib/payment_day/version.rb +1 -1
- data/lib/payment_day.rb +43 -9
- 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: 6e8eac69e44a25f3069daac105862597e6f763fbe4594828b5b5b1d6a500f5b5
|
4
|
+
data.tar.gz: ca33ec1cb95f81285f18fdaf6d77dccc4d75ebc11b4fb62689d1c0f38e974393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f40ba0b61cebf07ca5f8a2430f059bf52b9af6182a4bb4f6c38f7d9045771645e01074faf1cbcc8072f9c12acae43398322b148b78662fe44ecab85056e412
|
7
|
+
data.tar.gz: d4dd9e1c99c42e93197aeef849eb229c70fecb1ef3be93d09905af25667b648589af3ccf44c78b769e76bc733a1662ad69ef208d193b48c66bf107ac87a1aec1
|
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.2)
|
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,43 @@ 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 | false
|
40
|
+
--columns | | -c | 10
|
41
|
+
--dayname | --no-dayname | -e | true
|
42
|
+
--duplicates | --no-duplicates | -d | false
|
43
|
+
--footer | --no-footer | -f | true
|
44
|
+
--header | --no-header | -h | true
|
45
|
+
--separator | --no-separator | -s | true
|
46
|
+
|
47
|
+
```bash
|
48
|
+
payment_day view 2023 2024 2025-2027
|
49
|
+
```
|
26
50
|
|
27
51
|
## Contributing
|
28
52
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/the-pulli/payment_day.
|
30
54
|
|
31
55
|
## License
|
32
56
|
|
data/lib/payment_day/cli.rb
CHANGED
@@ -6,11 +6,27 @@ require "thor"
|
|
6
6
|
module PaymentDay
|
7
7
|
# CLI class for PayDay
|
8
8
|
class CLI < Thor
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
def self.exit_on_failure?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "view YEARS", "Lists all pay days for the given year(s)"
|
14
|
+
method_option :ascii, aliases: "-a", type: :boolean, default: false, desc: "Do you want to have a ASCII table printed?"
|
15
|
+
method_option :columns, aliases: "-c", type: :numeric, default: 10, desc: "How many years (columns) do you wanna display in one table?"
|
16
|
+
method_option :dayname, aliases: "-e", type: :boolean, default: true, desc: "Do you want see the day name?"
|
17
|
+
method_option :duplicates, aliases: "-d", type: :boolean, default: false, desc: "Do you want see duplicates?"
|
18
|
+
method_option :footer, aliases: "-f", type: :boolean, default: true, desc: "Do you want see the table footer?"
|
19
|
+
method_option :header, aliases: "-h", type: :boolean, default: true, desc: "Do you wanna see the table title?"
|
20
|
+
method_option :separator, aliases: "-s", type: :boolean, default: true, desc: "Do you want to have a separator for the rows printed?"
|
21
|
+
def view(*years)
|
22
|
+
years = PaymentDay::View.new(years, options).years
|
23
|
+
years = years.each_slice(options[:columns])
|
24
|
+
years.each_with_index do |yearsChunk, page|
|
25
|
+
year_options = options.dup
|
26
|
+
year_options[:page] = page.next
|
27
|
+
year_options[:pages] = years.to_a.length
|
28
|
+
puts PaymentDay::View.new(yearsChunk, year_options).list()
|
29
|
+
end
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|
data/lib/payment_day/version.rb
CHANGED
data/lib/payment_day.rb
CHANGED
@@ -8,24 +8,39 @@ require_relative "payment_day/version"
|
|
8
8
|
module PaymentDay
|
9
9
|
# View class
|
10
10
|
class View
|
11
|
-
|
11
|
+
DEFAULT_OPTIONS = {
|
12
|
+
ascii: false,
|
13
|
+
dayname: false,
|
14
|
+
duplicates: false,
|
15
|
+
footer: true,
|
16
|
+
page: nil,
|
17
|
+
pages: nil,
|
18
|
+
separator: true
|
19
|
+
}.freeze
|
12
20
|
|
13
|
-
attr_reader :pay_days
|
21
|
+
attr_reader :pay_days, :years
|
14
22
|
|
15
23
|
def initialize(*years)
|
16
24
|
options = years.last.is_a?(Hash) ? years.slice!(-1) : {}
|
17
|
-
@
|
25
|
+
@months = []
|
26
|
+
@options = DEFAULT_OPTIONS.merge options.transform_keys(&:to_sym)
|
27
|
+
@years = prepare_years(years)
|
18
28
|
@pay_days = find_pay_days
|
19
|
-
@options = { separator: true, ascii: false }.merge options.transform_keys(&:to_sym)
|
20
29
|
end
|
21
30
|
|
22
31
|
def list
|
23
32
|
Terminal::Table.new do |t|
|
24
33
|
t.title = Rainbow("Pay days").bright
|
25
|
-
t.headings = [Rainbow("Month").bright] + @years.map { |y| Rainbow(y).bright }
|
34
|
+
t.headings = [Rainbow("Month").bright] + @years.map { |y| { value: Rainbow(y).bright, alignment: :center } }
|
26
35
|
t.style = { all_separators: @options[:separator], border: border }
|
27
|
-
t.rows =
|
36
|
+
t.rows = @months.map { |m| Rainbow(m).cyan }.zip(*format_pay_days)
|
28
37
|
@years.each_index { |v| t.align_column v.next, :center }
|
38
|
+
page = @options[:page]
|
39
|
+
pages = @options[:pages]
|
40
|
+
if @options[:footer] && pages > 1
|
41
|
+
t.add_row [{ colspan: @years.length.next, value: "Page #{page}/#{pages}",
|
42
|
+
alignment: :center }]
|
43
|
+
end
|
29
44
|
end
|
30
45
|
end
|
31
46
|
|
@@ -34,7 +49,7 @@ module PaymentDay
|
|
34
49
|
private
|
35
50
|
|
36
51
|
def prepare_years(years)
|
37
|
-
years.flatten.map do |year|
|
52
|
+
result = years.flatten.map do |year|
|
38
53
|
case year
|
39
54
|
when Range
|
40
55
|
year.to_a
|
@@ -49,19 +64,38 @@ module PaymentDay
|
|
49
64
|
year
|
50
65
|
end
|
51
66
|
end.flatten
|
67
|
+
|
68
|
+
result = result.uniq unless @options[:duplicates]
|
69
|
+
Array(result)
|
52
70
|
end
|
53
71
|
|
54
72
|
def find_pay_days
|
55
|
-
@
|
73
|
+
unless @options[:duplicates]
|
74
|
+
year_hsh = {}
|
75
|
+
@years.each.with_index do |year, index|
|
76
|
+
year_hsh[year] = (1..12).to_a.map do |month|
|
77
|
+
last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
|
78
|
+
@months.push(last_day.strftime("%B")) if index.zero?
|
79
|
+
prev(last_day)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
return year_hsh
|
83
|
+
end
|
84
|
+
|
85
|
+
@years.map.with_index do |year, index|
|
56
86
|
(1..12).to_a.map do |month|
|
57
87
|
last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
|
88
|
+
@months.push(last_day.strftime("%B")) if index.zero?
|
58
89
|
prev(last_day)
|
59
90
|
end
|
60
91
|
end
|
61
92
|
end
|
62
93
|
|
63
94
|
def format_pay_days
|
64
|
-
|
95
|
+
format = @options[:dayname] ? "%a, %d" : "%d"
|
96
|
+
return @pay_days.map { |_, year| year.map { |d| Rainbow(d.strftime(format)).green } } unless @options[:duplicates]
|
97
|
+
|
98
|
+
@pay_days.map { |year| year.map { |d| Rainbow(d.strftime(format)).green } }
|
65
99
|
end
|
66
100
|
|
67
101
|
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.
|
4
|
+
version: 0.2.0
|
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
|