payment_day 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 45a663cdf075d7c7b2043198b84d18e41105409918a238909c99d52879b12872
4
+ data.tar.gz: e12ce182fbd0ba9d6c82939eba73b6e755fa319f7e0d3c199271073f04339bd0
5
+ SHA512:
6
+ metadata.gz: 5ea056205c1df6e722cf7aa7b8c07b6b3fb9097078dfe6bceaf767733d232cf389521582b90f00e5bd596f45f485b981b2bacfb227fbd19cbd6675d2cdab5032
7
+ data.tar.gz: 1ca7add2eae81dd4e751b7b3a30217a88ec036b115bc1354531f969a14788c4a9796e023c55a2961caeb60bced181e193cad8f80eef019b4d34e7eeacfaa1eab
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-12-27
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pay_day.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pay_day (0.1.0)
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
+ pay_day!
26
+ rake (~> 13.0)
27
+
28
+ BUNDLED WITH
29
+ 2.4.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 PuLLi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # PayDay
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
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add pay_day
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install pay_day
16
+
17
+ ## Usage
18
+
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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pay_day.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
data/exe/payment_day ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "payment_day/cli"
5
+
6
+ PaymentDay::CLI.start
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "payment_day"
4
+ require "thor"
5
+
6
+ module PaymentDay
7
+ # CLI class for PayDay
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
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaymentDay
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "terminal-table"
5
+ require "rainbow"
6
+ require_relative "payment_day/version"
7
+
8
+ module PaymentDay
9
+ # View class
10
+ class View
11
+ MONTHS = %w[January February March April May June July August September October November December].freeze
12
+
13
+ attr_reader :pay_days
14
+
15
+ def initialize(*years)
16
+ options = years.last.is_a?(Hash) ? years.slice!(-1) : {}
17
+ @years = Array(prepare_years(years))
18
+ @pay_days = find_pay_days
19
+ @options = { separator: true, ascii: false }.merge options.transform_keys(&:to_sym)
20
+ end
21
+
22
+ def list
23
+ Terminal::Table.new do |t|
24
+ t.title = Rainbow("Pay days").bright
25
+ t.headings = [Rainbow("Month").bright] + @years.map { |y| Rainbow(y).bright }
26
+ t.style = { all_separators: @options[:separator], border: border }
27
+ t.rows = MONTHS.map { |m| Rainbow(m).cyan }.zip(*format_pay_days)
28
+ @years.each_index { |v| t.align_column v.next, :center }
29
+ end
30
+ end
31
+
32
+ alias show list
33
+
34
+ private
35
+
36
+ def prepare_years(years)
37
+ years.flatten.map do |year|
38
+ case year
39
+ when Range
40
+ year.to_a
41
+ when String
42
+ range = year.split("-")
43
+ if range.first.to_i <= range.last.to_i
44
+ Range.new(range.first, range.last).to_a
45
+ else
46
+ Range.new(range.last, range.first).to_a
47
+ end
48
+ else
49
+ year
50
+ end
51
+ end.flatten
52
+ end
53
+
54
+ def find_pay_days
55
+ @years.map do |year|
56
+ (1..12).to_a.map do |month|
57
+ last_day = Date.parse("#{year}-#{month}-01").next_month.prev_day
58
+ prev(last_day)
59
+ end
60
+ end
61
+ end
62
+
63
+ def format_pay_days
64
+ @pay_days.map { |year| year.map { |d| Rainbow(d.strftime("%d")).green } }
65
+ end
66
+
67
+ def prev(day)
68
+ return day if (1..5).include? day.wday
69
+
70
+ prev(day.prev_day)
71
+ end
72
+
73
+ def border
74
+ @options[:ascii] ? :ascii : :unicode_round
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/payment_day/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "payment_day"
7
+ spec.version = PaymentDay::VERSION
8
+ spec.authors = ["PuLLi"]
9
+ spec.email = ["the@pulli.dev"]
10
+
11
+ spec.summary = "Calculates the last working day of a month, which is usually pay day."
12
+ spec.description = "Prints out a nicely formatted table of pay days for the given year(s) with the CLI command. Or returns the pay days as an array of arrays sorted by their input."
13
+ spec.homepage = "https://github.com/the-pulli/payment_day"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/the-pulli/payment_day"
21
+ spec.metadata["changelog_uri"] = "https://github.com/the-pulli/payment_day/main/blob/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ spec.add_dependency "rainbow", "~> 3.1"
36
+ spec.add_dependency "terminal-table", "~> 3.0"
37
+ spec.add_dependency "thor", "~> 1.2"
38
+
39
+ # For more information and examples about making a new gem, check out our
40
+ # guide at: https://bundler.io/guides/creating_gem.html
41
+ end
data/sig/pay_day.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module PayDay
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payment_day
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - PuLLi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ description: Prints out a nicely formatted table of pay days for the given year(s)
56
+ with the CLI command. Or returns the pay days as an array of arrays sorted by their
57
+ input.
58
+ email:
59
+ - the@pulli.dev
60
+ executables:
61
+ - payment_day
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - exe/payment_day
72
+ - lib/payment_day.rb
73
+ - lib/payment_day/cli.rb
74
+ - lib/payment_day/version.rb
75
+ - payment_day.gemspec
76
+ - sig/pay_day.rbs
77
+ homepage: https://github.com/the-pulli/payment_day
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ homepage_uri: https://github.com/the-pulli/payment_day
83
+ source_code_uri: https://github.com/the-pulli/payment_day
84
+ changelog_uri: https://github.com/the-pulli/payment_day/main/blob/CHANGELOG.md
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 2.6.0
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.4.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Calculates the last working day of a month, which is usually pay day.
104
+ test_files: []