payment_day 0.2.1 → 0.2.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/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 -20
- 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: 9cff6548d69331df6551413e6022e1096cd9c98229bcc609c1d2eb4ff532411d
|
4
|
+
data.tar.gz: a794a8df445185ee98c59b8425cfdf9237a24fc384f6c21559be6699355d4d70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b211a666cddc455973b8e52705316ee9e854b8cbe1f5b88c371c412861b57749a2cb76dbff7b91c7a41ccb7dfd8c38b4f2a404231807670433fff2fdd1c87e
|
7
|
+
data.tar.gz: c65095ab77e8d6574e9aea507d7ca5b6e9356604b747d486fa19dbaffa62f730e74721d7e1fa8669b0253c2af0b78707612f156476a046844d7cbbc43fdaa4f9
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# PaymentDay
|
2
2
|
|
3
|
+
[](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,32 @@ 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
|
-
|
103
|
-
|
104
|
-
|
102
|
+
formatter = lambda { |d|
|
103
|
+
day = d.strftime(format)
|
104
|
+
format(day, :green)
|
105
|
+
}
|
106
|
+
|
107
|
+
p @pay_days.is_a?(Hash)
|
108
|
+
@pay_days.map do |_, years|
|
109
|
+
p years
|
110
|
+
# mapping_object = @options[:duplicates] ? year : days
|
111
|
+
years.map { |d| formatter.call(d) }
|
112
|
+
end
|
105
113
|
end
|
106
114
|
|
107
115
|
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.2
|
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
|