payment_day 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/README.md +4 -1
- data/lib/payment_day/cli.rb +3 -2
- data/lib/payment_day/version.rb +1 -1
- data/lib/payment_day.rb +28 -19
- 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: 4b26395b7673e9f79fdf77ced9dfc1f51bd32a9c949d35e400b3d13da3a3cf4c
|
4
|
+
data.tar.gz: f13e2ca28f0725f8ca61645cb243ba9bdff8e12300224c6e4ebe4d413e2b6e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb53d3f53f206989b46b007be73ecdf5ce156155343efa2c8c7fd8e03cb8da7495b73d0c6f91476cfa44b25a9feb48756835ca62666e05052c16bb5a2164fdee
|
7
|
+
data.tar.gz: f62e9ec7280afaaf7b1eb95a48f0b0bb14a2b2e170f3c014f46b34f24933975163a0bb79c9af2ad475aa8cae562aeb28345b6bcfdc28ba2227454d2f627cf3ee
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.3] - 2023-01-07
|
4
|
+
|
5
|
+
- fix broken format_pay_days method
|
6
|
+
|
7
|
+
## [0.2.2] - 2023-01-07
|
8
|
+
|
9
|
+
- payment_day add colors option
|
10
|
+
- Refactoring
|
11
|
+
|
12
|
+
## [0.2.0 - 0.2.1] - 2023-01-01
|
13
|
+
|
14
|
+
- Refactoring
|
15
|
+
|
3
16
|
## [0.1.12] - 2022-12-31
|
4
17
|
|
5
18
|
- Refactoring
|
6
|
-
-
|
19
|
+
- payment_day executable supports more options
|
7
20
|
|
8
21
|
## [0.1.11] - 2022-12-28
|
9
22
|
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# PaymentDay
|
2
2
|
|
3
|
+
[![Build Status](https://app.travis-ci.com/the-pulli/payment_day.svg?branch=main)](https://app.travis-ci.com/the-pulli/payment_day)
|
4
|
+
|
3
5
|
Provides a class PaymentDay::View. This class generates the pay days for the given year(s).
|
4
6
|
|
5
7
|
## Installation
|
@@ -28,7 +30,7 @@ PaymentDay::View.create(2023..2024, 2025, '2026').pay_days # accept a mix of all
|
|
28
30
|
# shows 2023 twice in the list of pay_days, default is false
|
29
31
|
PaymentDay::View.create(2023..2024, 2023, duplicates: true).pay_days
|
30
32
|
|
31
|
-
table = PaymentDay::View(2023).list # returns a Terminal::Table instance
|
33
|
+
table = PaymentDay::View.create(2023).list # returns a Terminal::Table instance
|
32
34
|
puts table # which can be printed like this
|
33
35
|
```
|
34
36
|
|
@@ -37,6 +39,7 @@ puts table # which can be printed like this
|
|
37
39
|
Option | Negated | Shortcut | Default
|
38
40
|
--- | ---: | ---: | ---:
|
39
41
|
--ascii | --no-ascii | -a | false
|
42
|
+
--colors | --no-colors | | true
|
40
43
|
--columns | | -c | 10
|
41
44
|
--dayname | --no-dayname | -e | true
|
42
45
|
--duplicates | --no-duplicates | -d | false
|
data/lib/payment_day/cli.rb
CHANGED
@@ -13,6 +13,7 @@ module PaymentDay
|
|
13
13
|
desc "view YEARS", "Lists all pay days for the given year(s)"
|
14
14
|
method_option :ascii, aliases: "-a", type: :boolean, default: false, desc: "Do you want to have a ASCII table printed?"
|
15
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 :colors, type: :boolean, default: true, desc: "Do you want colored output?"
|
16
17
|
method_option :dayname, aliases: "-e", type: :boolean, default: true, desc: "Do you want see the day name?"
|
17
18
|
method_option :duplicates, aliases: "-d", type: :boolean, default: false, desc: "Do you want see duplicates?"
|
18
19
|
method_option :footer, aliases: "-f", type: :boolean, default: true, desc: "Do you want see the table footer?"
|
@@ -21,11 +22,11 @@ module PaymentDay
|
|
21
22
|
def view(*years)
|
22
23
|
years = PaymentDay::View.create(years, options).years
|
23
24
|
years = years.each_slice(options[:columns])
|
24
|
-
years.each_with_index do |
|
25
|
+
years.each_with_index do |years_chunk, page|
|
25
26
|
year_options = options.dup
|
26
27
|
year_options[:page] = page.next
|
27
28
|
year_options[:pages] = years.to_a.length
|
28
|
-
puts PaymentDay::View.create(
|
29
|
+
puts PaymentDay::View.create(years_chunk, year_options).list
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
data/lib/payment_day/version.rb
CHANGED
data/lib/payment_day.rb
CHANGED
@@ -10,6 +10,8 @@ module PaymentDay
|
|
10
10
|
class View
|
11
11
|
DEFAULT_OPTIONS = {
|
12
12
|
ascii: false,
|
13
|
+
colors: true,
|
14
|
+
columns: 10,
|
13
15
|
dayname: false,
|
14
16
|
duplicates: false,
|
15
17
|
footer: true,
|
@@ -36,10 +38,12 @@ module PaymentDay
|
|
36
38
|
|
37
39
|
def list
|
38
40
|
Terminal::Table.new do |t|
|
39
|
-
t.title =
|
40
|
-
t.headings = [
|
41
|
+
t.title = format("Pay days", :bright)
|
42
|
+
t.headings = [format("Month", :bright)] + @years.map do |y|
|
43
|
+
{ value: format(y, :bright), alignment: :center }
|
44
|
+
end
|
41
45
|
t.style = { all_separators: @options[:separator], border: border }
|
42
|
-
t.rows = @months.map { |m|
|
46
|
+
t.rows = @months.map { |m| format(m, :cyan) }.zip(*format_pay_days)
|
43
47
|
@years.each_index { |v| t.align_column v.next, :center }
|
44
48
|
page = @options[:page]
|
45
49
|
pages = @options[:pages]
|
@@ -54,6 +58,10 @@ module PaymentDay
|
|
54
58
|
|
55
59
|
private
|
56
60
|
|
61
|
+
def format(value, color)
|
62
|
+
@options[:colors] ? Rainbow(value).send(color) : value
|
63
|
+
end
|
64
|
+
|
57
65
|
def prepare_years(years)
|
58
66
|
result = years.flatten.map do |year|
|
59
67
|
case year
|
@@ -76,32 +84,33 @@ module PaymentDay
|
|
76
84
|
end
|
77
85
|
|
78
86
|
def find_pay_days
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
year_hsh[year] = (1..12).to_a.map do |month|
|
83
|
-
last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
|
84
|
-
@months.push(last_day.strftime("%B")) if index.zero?
|
85
|
-
prev(last_day)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
return year_hsh
|
89
|
-
end
|
90
|
-
|
91
|
-
@years.map.with_index do |year, index|
|
92
|
-
(1..12).to_a.map do |month|
|
87
|
+
year_hsh = {}
|
88
|
+
years_ary = @years.map.with_index do |year, index|
|
89
|
+
year_hsh[year] = (1..12).to_a.map do |month|
|
93
90
|
last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
|
94
91
|
@months.push(last_day.strftime("%B")) if index.zero?
|
95
92
|
prev(last_day)
|
96
93
|
end
|
97
94
|
end
|
95
|
+
return years_ary if @options[:duplicates]
|
96
|
+
|
97
|
+
year_hsh
|
98
98
|
end
|
99
99
|
|
100
100
|
def format_pay_days
|
101
101
|
format = @options[:dayname] ? "%a, %d" : "%d"
|
102
|
-
|
102
|
+
formatter = lambda { |days|
|
103
|
+
days.map do |d|
|
104
|
+
day = d.strftime(format)
|
105
|
+
format(day, :green)
|
106
|
+
end
|
107
|
+
}
|
103
108
|
|
104
|
-
@
|
109
|
+
if @options[:duplicates]
|
110
|
+
@pay_days.map { |days| formatter.call(days) }
|
111
|
+
else
|
112
|
+
@pay_days.map { |_, days| formatter.call(days) }
|
113
|
+
end
|
105
114
|
end
|
106
115
|
|
107
116
|
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PuLLi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|