class WoerkClient::Commands::GetStatus

Public Instance Methods

call() click to toggle source
# File lib/woerk_client/commands/get_status.rb, line 6
def call
  status
rescue RestClient::ExceptionWithResponse => e
  errors.add(:start, e.message)
end

Private Instance Methods

current_shift() click to toggle source

Fetches the current shift from the shifts array

@return [Hash] The current shift

# File lib/woerk_client/commands/get_status.rb, line 42
def current_shift
  @current ||= shifts.find { |s| s['stopped_at'] == 0 }
end
current_working_duration() click to toggle source

@return [String] Current working duration

# File lib/woerk_client/commands/get_status.rb, line 21
def current_working_duration
  return '-' if current_shift.nil?

  start = current_shift['started_at']/1000
  diff  = (Time.now.to_i - start)/60

  "#{diff} minutes".colorize(:green)
end
currently_working?() click to toggle source

Rerturns the answer as String

@return [String]

# File lib/woerk_client/commands/get_status.rb, line 34
def currently_working?
  current_shift.nil? ? 'no'.colorize(:red) : 'yes'.colorize(:green)
end
shifts() click to toggle source

Gets all the shifts

@return [Array] All shifts as Hashes

# File lib/woerk_client/commands/get_status.rb, line 50
def shifts
  @shifts ||= JSON.parse(
    WoerkClient::Client.get(WoerkClient::Models::Shift::RESOURCE_PATH)
  )
end
status() click to toggle source

@return [String] The current status

# File lib/woerk_client/commands/get_status.rb, line 15
      def status
        %Q(Currently working? #{currently_working?}
Working since #{current_working_duration})
      end