pto 0.0.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 +7 -0
 - data/bin/pto +77 -0
 - metadata +44 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d180d119e1f1b5b66163fbaeb1336b7e740edf53e3a25ec6c3de46311f965f1d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: '068f57a398f5dade3702dc165344e2d7a7705b9e5b66750bfd8016f838cdc85d'
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: eedd1ac8f77c5c9a2869cb894d6ad31024217747ddb87399225d29663507549d7a3b79e499d663fcb2e3acb68e53ed4850bc9e1e0baf1d60ef47737e0aaa562f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2e1400872b68c20153d0f97752da5819763d74f3905b7a35d3d245f01b48273198036649a43e3ec3dad0b433bbe340095145f98ed69d62736040832dc1534925
         
     | 
    
        data/bin/pto
    ADDED
    
    | 
         @@ -0,0 +1,77 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'optparse'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'date'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            def convert(str)
         
     | 
| 
      
 7 
     | 
    
         
            +
              case str
         
     | 
| 
      
 8 
     | 
    
         
            +
              when /(.*)\/(.*)/
         
     | 
| 
      
 9 
     | 
    
         
            +
                return Float($1) / Float($2)
         
     | 
| 
      
 10 
     | 
    
         
            +
              when /(.*)\.(.*)/
         
     | 
| 
      
 11 
     | 
    
         
            +
                return Float(str)
         
     | 
| 
      
 12 
     | 
    
         
            +
              else
         
     | 
| 
      
 13 
     | 
    
         
            +
                return Integer(str)
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            def days_until_cap(accrual:, cap:, rate:)
         
     | 
| 
      
 18 
     | 
    
         
            +
              days = 0
         
     | 
| 
      
 19 
     | 
    
         
            +
              return days if accrual >= cap
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              daily_rate = rate / 365.0
         
     | 
| 
      
 22 
     | 
    
         
            +
              while accrual < cap
         
     | 
| 
      
 23 
     | 
    
         
            +
                accrual += daily_rate
         
     | 
| 
      
 24 
     | 
    
         
            +
                days += 1
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
              days
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            def main(options = {})
         
     | 
| 
      
 30 
     | 
    
         
            +
              accrual = convert(options[:accrual])
         
     | 
| 
      
 31 
     | 
    
         
            +
              cap = convert(options[:cap])
         
     | 
| 
      
 32 
     | 
    
         
            +
              rate = convert(options[:rate])
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              days = days_until_cap(accrual: accrual, cap: cap, rate: rate)
         
     | 
| 
      
 35 
     | 
    
         
            +
              if days == 0
         
     | 
| 
      
 36 
     | 
    
         
            +
                puts "Already over cap :-( Please take some PTO ASAP!"
         
     | 
| 
      
 37 
     | 
    
         
            +
              else
         
     | 
| 
      
 38 
     | 
    
         
            +
                cap_date = Date.today + days
         
     | 
| 
      
 39 
     | 
    
         
            +
                puts "Cap is hit in #{days} days - on #{cap_date}. Please take some PTO before then :-)"
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
              return true
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            options = {}
         
     | 
| 
      
 46 
     | 
    
         
            +
            optparse = OptionParser.new do |opts|
         
     | 
| 
      
 47 
     | 
    
         
            +
              opts.on("-aACCRUAL", "--accrual=ACCRUAL", "Set current accrual in number of days. Defaults to zero.") do |accrual|
         
     | 
| 
      
 48 
     | 
    
         
            +
                options[:accrual] = accrual
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
              opts.on("-cCAP", "--cap=CAP", "Set cap in number of days. Required argument.") do |cap|
         
     | 
| 
      
 51 
     | 
    
         
            +
                options[:cap] = cap
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
              opts.on("-rRATE", "--rate=RATE", "Set accrual rate in number of days per year. Required argument.") do |rate|
         
     | 
| 
      
 54 
     | 
    
         
            +
                options[:rate] = rate
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
              opts.on("-h", "--help", "Prints this help") do
         
     | 
| 
      
 57 
     | 
    
         
            +
                puts opts
         
     | 
| 
      
 58 
     | 
    
         
            +
                exit
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
            end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            begin
         
     | 
| 
      
 63 
     | 
    
         
            +
              optparse.parse!
         
     | 
| 
      
 64 
     | 
    
         
            +
              mandatory = [:cap, :rate]
         
     | 
| 
      
 65 
     | 
    
         
            +
              missing = mandatory.select{ |param| options[param].nil? }
         
     | 
| 
      
 66 
     | 
    
         
            +
              unless missing.empty?
         
     | 
| 
      
 67 
     | 
    
         
            +
                raise OptionParser::MissingArgument.new(missing.join(', '))
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
            rescue OptionParser::InvalidOption, OptionParser::MissingArgument
         
     | 
| 
      
 70 
     | 
    
         
            +
              puts $!.to_s
         
     | 
| 
      
 71 
     | 
    
         
            +
              puts optparse
         
     | 
| 
      
 72 
     | 
    
         
            +
              exit
         
     | 
| 
      
 73 
     | 
    
         
            +
            end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            options[:accrual] = 0.0 if options[:accrual].nil?
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            main(options)
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: pto
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Magne Land
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-01-08 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description:
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: magne.land@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables:
         
     | 
| 
      
 16 
     | 
    
         
            +
            - pto
         
     | 
| 
      
 17 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 19 
     | 
    
         
            +
            files:
         
     | 
| 
      
 20 
     | 
    
         
            +
            - bin/pto
         
     | 
| 
      
 21 
     | 
    
         
            +
            homepage: https://github.com/magneland/pto
         
     | 
| 
      
 22 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 23 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 24 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 25 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
      
 26 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 27 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 28 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 29 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 34 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 35 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 36 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 37 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 38 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 39 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 40 
     | 
    
         
            +
            rubygems_version: 3.1.3
         
     | 
| 
      
 41 
     | 
    
         
            +
            signing_key:
         
     | 
| 
      
 42 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 43 
     | 
    
         
            +
            summary: Calculate your future Paid Time Off (PTO) accrual
         
     | 
| 
      
 44 
     | 
    
         
            +
            test_files: []
         
     |