payment_day 0.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e8eac69e44a25f3069daac105862597e6f763fbe4594828b5b5b1d6a500f5b5
4
- data.tar.gz: ca33ec1cb95f81285f18fdaf6d77dccc4d75ebc11b4fb62689d1c0f38e974393
3
+ metadata.gz: 9cff6548d69331df6551413e6022e1096cd9c98229bcc609c1d2eb4ff532411d
4
+ data.tar.gz: a794a8df445185ee98c59b8425cfdf9237a24fc384f6c21559be6699355d4d70
5
5
  SHA512:
6
- metadata.gz: 07f40ba0b61cebf07ca5f8a2430f059bf52b9af6182a4bb4f6c38f7d9045771645e01074faf1cbcc8072f9c12acae43398322b148b78662fe44ecab85056e412
7
- data.tar.gz: d4dd9e1c99c42e93197aeef849eb229c70fecb1ef3be93d09905af25667b648589af3ccf44c78b769e76bc733a1662ad69ef208d193b48c66bf107ac87a1aec1
6
+ metadata.gz: 53b211a666cddc455973b8e52705316ee9e854b8cbe1f5b88c371c412861b57749a2cb76dbff7b91c7a41ccb7dfd8c38b4f2a404231807670433fff2fdd1c87e
7
+ data.tar.gz: c65095ab77e8d6574e9aea507d7ca5b6e9356604b747d486fa19dbaffa62f730e74721d7e1fa8669b0253c2af0b78707612f156476a046844d7cbbc43fdaa4f9
data/README.md CHANGED
@@ -1,34 +1,36 @@
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
6
8
 
7
9
  Install the gem and add to the application's Gemfile by executing:
8
10
 
9
- $ bundle add pay_day
11
+ $ bundle add payment_day
10
12
 
11
13
  If bundler is not being used to manage dependencies, install the gem by executing:
12
14
 
13
- $ gem install pay_day
15
+ $ gem install payment_day
14
16
 
15
17
  ## Usage
16
18
 
17
19
  ```ruby
18
20
  # 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
21
+ PaymentDay::View.create(2023).pay_days # return Array of Hash(es) with the pay_days
22
+ PaymentDay::View.create("2023").pay_days # accept String as input
23
+ PaymentDay::View.create(2023, 2024).pay_days # accept multiple years
24
+ PaymentDay::View.create([2023]).pay_days # accept Array's as input
25
+ PaymentDay::View.create("2023-2024").pay_days # accept String ranges
26
+ PaymentDay::View.create(2023..2024).pay_days # accept Range as input
27
+ PaymentDay::View.create(2023..2024, 2025, '2026').pay_days # accept a mix of all of them
26
28
 
27
29
  # Last parameter defines the options if set
28
30
  # shows 2023 twice in the list of pay_days, default is false
29
- PaymentDay::View(2023..2024, 2023, duplicates: true).pay_days
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
@@ -13,19 +13,20 @@ 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?"
19
20
  method_option :header, aliases: "-h", type: :boolean, default: true, desc: "Do you wanna see the table title?"
20
21
  method_option :separator, aliases: "-s", type: :boolean, default: true, desc: "Do you want to have a separator for the rows printed?"
21
22
  def view(*years)
22
- years = PaymentDay::View.new(years, options).years
23
+ years = PaymentDay::View.create(years, options).years
23
24
  years = years.each_slice(options[:columns])
24
- years.each_with_index do |yearsChunk, page|
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.new(yearsChunk, year_options).list()
29
+ puts PaymentDay::View.create(years_chunk, year_options).list
29
30
  end
30
31
  end
31
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaymentDay
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
5
5
  end
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,
@@ -18,6 +20,8 @@ module PaymentDay
18
20
  separator: true
19
21
  }.freeze
20
22
 
23
+ private_class_method :new
24
+
21
25
  attr_reader :pay_days, :years
22
26
 
23
27
  def initialize(*years)
@@ -28,12 +32,18 @@ module PaymentDay
28
32
  @pay_days = find_pay_days
29
33
  end
30
34
 
35
+ def self.create(*years)
36
+ new(*years)
37
+ end
38
+
31
39
  def list
32
40
  Terminal::Table.new do |t|
33
- t.title = Rainbow("Pay days").bright
34
- t.headings = [Rainbow("Month").bright] + @years.map { |y| { value: Rainbow(y).bright, alignment: :center } }
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
35
45
  t.style = { all_separators: @options[:separator], border: border }
36
- t.rows = @months.map { |m| Rainbow(m).cyan }.zip(*format_pay_days)
46
+ t.rows = @months.map { |m| format(m, :cyan) }.zip(*format_pay_days)
37
47
  @years.each_index { |v| t.align_column v.next, :center }
38
48
  page = @options[:page]
39
49
  pages = @options[:pages]
@@ -48,6 +58,10 @@ module PaymentDay
48
58
 
49
59
  private
50
60
 
61
+ def format(value, color)
62
+ @options[:colors] ? Rainbow(value).send(color) : value
63
+ end
64
+
51
65
  def prepare_years(years)
52
66
  result = years.flatten.map do |year|
53
67
  case year
@@ -70,32 +84,32 @@ module PaymentDay
70
84
  end
71
85
 
72
86
  def find_pay_days
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|
86
- (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|
87
90
  last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
88
91
  @months.push(last_day.strftime("%B")) if index.zero?
89
92
  prev(last_day)
90
93
  end
91
94
  end
95
+ return years_ary if @options[:duplicates]
96
+
97
+ year_hsh
92
98
  end
93
99
 
94
100
  def format_pay_days
95
101
  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 } }
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
99
113
  end
100
114
 
101
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.0
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: 2022-12-31 00:00:00.000000000 Z
11
+ date: 2023-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -64,7 +64,6 @@ extra_rdoc_files: []
64
64
  files:
65
65
  - CHANGELOG.md
66
66
  - Gemfile
67
- - Gemfile.lock
68
67
  - LICENSE.txt
69
68
  - README.md
70
69
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,29 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- payment_day (0.1.2)
5
- rainbow (~> 3.1)
6
- terminal-table (~> 3.0)
7
- thor (~> 1.2)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- minitest (5.16.3)
13
- rainbow (3.1.1)
14
- rake (13.0.6)
15
- terminal-table (3.0.2)
16
- unicode-display_width (>= 1.1.1, < 3)
17
- thor (1.2.1)
18
- unicode-display_width (2.3.0)
19
-
20
- PLATFORMS
21
- arm64-darwin-22
22
-
23
- DEPENDENCIES
24
- minitest (~> 5.0)
25
- payment_day!
26
- rake (~> 13.0)
27
-
28
- BUNDLED WITH
29
- 2.4.1