payment_day 0.1.1 → 0.2.0

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: f831e07338ecf125bda97e4c77b9f0968c4cb4c60625addfecb5bedbfd906c4c
4
- data.tar.gz: 41200c85a4bce203446ab8a66936eeb0fa39609acbad4cb703d3432a646a526d
3
+ metadata.gz: 6e8eac69e44a25f3069daac105862597e6f763fbe4594828b5b5b1d6a500f5b5
4
+ data.tar.gz: ca33ec1cb95f81285f18fdaf6d77dccc4d75ebc11b4fb62689d1c0f38e974393
5
5
  SHA512:
6
- metadata.gz: f72f3c88895c8a5e38a5811af9ba180172833412c739e000f68d8586e338bc9a8e25232dccebe2723edeeb432694da3ed291e29834892342923d8a0d3541cba3
7
- data.tar.gz: d0fbf52275d7298466fbbc11343ddecec8f95c637769f623a746a704d50aea634e623a1a760d92d65887fe554ba012ee6db5026915e8fb2c8426e40d574fd9da
6
+ metadata.gz: 07f40ba0b61cebf07ca5f8a2430f059bf52b9af6182a4bb4f6c38f7d9045771645e01074faf1cbcc8072f9c12acae43398322b148b78662fe44ecab85056e412
7
+ data.tar.gz: d4dd9e1c99c42e93197aeef849eb229c70fecb1ef3be93d09905af25667b648589af3ccf44c78b769e76bc733a1662ad69ef208d193b48c66bf107ac87a1aec1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.12] - 2022-12-31
4
+
5
+ - Refactoring
6
+ - pay_day executable supports more options
7
+
8
+ ## [0.1.11] - 2022-12-28
9
+
10
+ - Refactoring
11
+
3
12
  ## [0.1.0] - 2022-12-27
4
13
 
5
14
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pay_day (0.1.0)
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
- pay_day!
25
+ payment_day!
26
26
  rake (~> 13.0)
27
27
 
28
28
  BUNDLED WITH
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # PayDay
1
+ # PaymentDay
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pay_day`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
20
-
21
- ## Development
22
-
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
-
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/pay_day.
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
 
@@ -6,11 +6,27 @@ require "thor"
6
6
  module PaymentDay
7
7
  # CLI class for PayDay
8
8
  class CLI < Thor
9
- desc "list", "Lists all pay days for the given year(s)"
10
- method_option :ascii, aliases: "-a", type: :boolean, default: false
11
- method_option :separator, aliases: "-s", type: :boolean, default: true
12
- def list(*years)
13
- puts PaymentDay::View.new(years, options).list
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaymentDay
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
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
- MONTHS = %w[January February March April May June July August September October November December].freeze
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
- @years = Array(prepare_years(years))
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 = MONTHS.map { |m| Rainbow(m).cyan }.zip(*format_pay_days)
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
- @years.map do |year|
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
- @pay_days.map { |year| year.map { |d| Rainbow(d.strftime("%d")).green } }
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.1.1
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-27 00:00:00.000000000 Z
11
+ date: 2022-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow