Sha256: 3bdad3545e689503068e90a7bb920c9be12015fc975ae83f9fd30b7160cdd9f5

Contents?: true

Size: 924 Bytes

Versions: 2

Compression:

Stored size: 924 Bytes

Contents

# frozen_string_literal: true

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

        def execute
          punch_dates.each do |date|
            if date.saturday? || date.sunday?
              $stdout.puts "#{date} # WEEKEND"
            elsif holiday?(date)
              $stdout.puts "#{date} # HOLIDAY"
            else
              @interactor.punch(date)
            end
          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_punch) + 1
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
balboa-0.1.1 lib/balboa/cli/command/make_punch_command.rb
balboa-0.1.0 lib/balboa/cli/command/make_punch_command.rb