Sha256: 7e241370496d39c5ed9689c23bcd2f03c634eee3d9cc77274b4c1202e5e0602a

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require_relative 'capybara_interactor'
require_relative 'command/fetch_last_punch_command'
require_relative 'command/fill_punch_command'
require_relative 'command/login_command'
require_relative '../schedule'

module Balboa
  module Interactor
    class InteractorBuilder
      def self.create(*args)
        new(*args).create
      end

      def initialize(options)
        @options = options
        @interactor = CapybaraInteractor.new(options)
      end

      def create
        last_punch = Command::FetchLastPunchCommand.new

        @interactor.tap do |itr|
          itr.add_command(:punch, fill_punch)
          itr.add_command(:last, last_punch)
          itr.add_command(:login, login)
        end
      end

      private

      def schedule
        Balboa::Schedule.new(@options['start_at'],
                             @options['lunch_at'],
                             @options['restart_at'],
                             @options['leave_at'])
      end

      def fill_punch
        Command::FillPunchCommand.new(schedule, @options['project'])
      end

      def login
        Command::LoginCommand.new(@options['email'], @options['password'])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
balboa-0.1.7 lib/balboa/interactor/interactor_builder.rb