Sha256: 65d11e8ce2cd305e060244dc130ea396cc974fe024da24d3306c214bd03e6d87

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

module Balboa
  module CLI
    module Command
      class PunchCommand
        def initialize(interactor, holidays)
          @interactor = interactor
          @holidays = holidays.uniq.map { |holiday| Date.parse(holiday) }
        end

        def execute
          punch_dates.each do |date|
            $stdout.print(date.strftime("%d/%m/%Y"))

            if date.saturday? || date.sunday? || holiday?(date)
              $stdout.print(" # SKIPPED")
            else
              @interactor.punch(date)
            end

            $stdout.print("\n")
          end
        end

        private

        def punch_dates
          yesterday = Date.today - 1

          (last_punch_date..yesterday)
        end

        def holiday?(date)
          @holidays.include?(date)
        end

        def last_punch_date
          Date.parse(@interactor.last) + 1
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
balboa-0.1.2 lib/balboa/cli/command/punch_command.rb