payment_day 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a279d6517217a079c005e643cf8ed2800d5738c870f46143debd39d30a6cf8d1
4
- data.tar.gz: dcf679700489acc4548e0c008f6a23cd61d08bfa9bc934bcb16ca16c81c04142
3
+ metadata.gz: 473ff17dc41c8fe9778cb7f81ad6d5d563eb1ae8a62a83f6cc535e3b0dcd76d8
4
+ data.tar.gz: f8080f220c6816d42f7588ce612ce22948e0b678f0b54c2dcdace2f9051cb314
5
5
  SHA512:
6
- metadata.gz: 465d44ca851085f3bfc56ffdd14eb877a56baa625abad29fb8787d5c94bf5eab8e579a9595ff6538afe01baa50f9c091cf962c7e675751dadc73f1e72eca8ca5
7
- data.tar.gz: f113f82e0799a51150959e007bd64db74e78fb2d243487414cd8bc1d5ecc37301c145e5c42ecebe9b4514b19b9797a4a6535a4fe3cb136e97dc2a91acf249f2a
6
+ metadata.gz: 336accb29ed0eaf542c978da383bb9233084071bb57fcd116e3ab573f62dc4e33c8283c1594835315c05d2bd87c9c0c082a98fc01e8503c9840524c279bcae25
7
+ data.tar.gz: 1b2a327752a17619233ad74985d9844b37da95aa8704bb838f5ae4a0a10a56832b441896dd703ccb20cc3a722c7b68016921308f957bb1f2280abd224884b2d8
data/README.md CHANGED
@@ -6,27 +6,27 @@ Provides a class PaymentDay::View. This class generates the pay days for the giv
6
6
 
7
7
  Install the gem and add to the application's Gemfile by executing:
8
8
 
9
- $ bundle add pay_day
9
+ $ bundle add payment_day
10
10
 
11
11
  If bundler is not being used to manage dependencies, install the gem by executing:
12
12
 
13
- $ gem install pay_day
13
+ $ gem install payment_day
14
14
 
15
15
  ## Usage
16
16
 
17
17
  ```ruby
18
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
19
+ PaymentDay::View.create(2023).pay_days # return Array of Hash(es) with the pay_days
20
+ PaymentDay::View.create("2023").pay_days # accept String as input
21
+ PaymentDay::View.create(2023, 2024).pay_days # accept multiple years
22
+ PaymentDay::View.create([2023]).pay_days # accept Array's as input
23
+ PaymentDay::View.create("2023-2024").pay_days # accept String ranges
24
+ PaymentDay::View.create(2023..2024).pay_days # accept Range as input
25
+ PaymentDay::View.create(2023..2024, 2025, '2026').pay_days # accept a mix of all of them
26
26
 
27
27
  # Last parameter defines the options if set
28
28
  # shows 2023 twice in the list of pay_days, default is false
29
- PaymentDay::View(2023..2024, 2023, duplicates: true).pay_days
29
+ PaymentDay::View.create(2023..2024, 2023, duplicates: true).pay_days
30
30
 
31
31
  table = PaymentDay::View(2023).list # returns a Terminal::Table instance
32
32
  puts table # which can be printed like this
@@ -36,15 +36,16 @@ puts table # which can be printed like this
36
36
 
37
37
  Option | Negated | Shortcut | Default
38
38
  --- | ---: | ---: | ---:
39
- --ascii | --no-ascii | (-a) | [default: false]
40
- --columns | | (-c) | [default: 10]
41
- --dayname | --no-dayname | (-n) | [default: true]
42
- --duplicates | --no-duplicates | (-d) | [default: false]
43
- --footer | --no-footer | (-f) | [default: true]
44
- --separator | --no-separator | (-s) | [default: true]
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
45
46
 
46
47
  ```bash
47
- payment_day list 2023 2024 2025-2027
48
+ payment_day view 2023 2024 2025-2027
48
49
  ```
49
50
 
50
51
  ## Contributing
@@ -6,21 +6,26 @@ 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 :columns, aliases: "-c", type: :numeric, default: 10
12
- method_option :dayname, aliases: "-n", type: :boolean, default: true
13
- method_option :duplicates, aliases: "-d", type: :boolean, default: false
14
- method_option :footer, aliases: "-f", type: :boolean, default: true
15
- method_option :separator, aliases: "-s", type: :boolean, default: true
16
- def list(*years)
17
- years = PaymentDay::View.new(years, options).years
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.create(years, options).years
18
23
  years = years.each_slice(options[:columns])
19
24
  years.each_with_index do |yearsChunk, page|
20
25
  year_options = options.dup
21
26
  year_options[:page] = page.next
22
27
  year_options[:pages] = years.to_a.length
23
- puts PaymentDay::View.new(yearsChunk, year_options).list()
28
+ puts PaymentDay::View.create(yearsChunk, year_options).list()
24
29
  end
25
30
  end
26
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaymentDay
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/payment_day.rb CHANGED
@@ -8,17 +8,32 @@ require_relative "payment_day/version"
8
8
  module PaymentDay
9
9
  # View class
10
10
  class View
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
20
+
21
+ private_class_method :new
22
+
11
23
  attr_reader :pay_days, :years
12
24
 
13
25
  def initialize(*years)
14
- default_options = { separator: true, ascii: false, dayname: false, page: nil, pages: nil, duplicates: false, footer: true }
15
26
  options = years.last.is_a?(Hash) ? years.slice!(-1) : {}
16
27
  @months = []
17
- @options = default_options.merge options.transform_keys(&:to_sym)
28
+ @options = DEFAULT_OPTIONS.merge options.transform_keys(&:to_sym)
18
29
  @years = prepare_years(years)
19
30
  @pay_days = find_pay_days
20
31
  end
21
32
 
33
+ def self.create(*years)
34
+ new(*years)
35
+ end
36
+
22
37
  def list
23
38
  Terminal::Table.new do |t|
24
39
  t.title = Rainbow("Pay days").bright
@@ -28,7 +43,7 @@ module PaymentDay
28
43
  @years.each_index { |v| t.align_column v.next, :center }
29
44
  page = @options[:page]
30
45
  pages = @options[:pages]
31
- unless !@options[:footer] || (page.nil? || (page == 1 && pages == 1))
46
+ if @options[:footer] && pages > 1
32
47
  t.add_row [{ colspan: @years.length.next, value: "Page #{page}/#{pages}",
33
48
  alignment: :center }]
34
49
  end
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.2
4
+ version: 0.2.1
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-01 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.1)
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