Sha256: 653c77b77fd4a17bcbff6b3aa5ca9b280d9b2ce46d5f64991a140b2e5fa35e11

Contents?: true

Size: 757 Bytes

Versions: 1

Compression:

Stored size: 757 Bytes

Contents

# frozen_string_literal: true

require 'holidays'

module Balboa
  class PunchDate
    def initialize(date, cli)
      @date = date
      @cli = cli
      @holiday = Hash(Holidays.on(date, :br).first)
    end

    def punchable?
      if weekend?
        false
      elsif holiday?
        ask_for_punch
      else
        true
      end
    end

    def to_s
      @date.to_s
    end

    def strftime(format)
      @date.strftime(format)
    end

    def to_date
      @date
    end

    private

    def ask_for_punch
      @cli.agree(" #{holiday_name}. Punch? (y|n) ")
    end

    def holiday_name
      @holiday[:name]
    end

    def holiday?
      !@holiday.empty?
    end

    def weekend?
      @date.sunday? || @date.saturday?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
balboa-0.1.7 lib/balboa/punch_date.rb