Class: Gitlab::QuickActions::SpendTimeAndDateSeparator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/quick_actions/spend_time_and_date_separator.rb

Overview

This class takes spend command argument and separates date and time from spend command arguments if it present example: spend_command_time_and_date = “15m 2017-01-02” SpendTimeAndDateSeparator.new(spend_command_time_and_date).execute

> [900, Mon, 02 Jan 2017]

if date doesn’t present return time with current date in other cases return nil

Constant Summary collapse

DATE_REGEX =
%r{(\d{2,4}[/\-.]\d{1,2}[/\-.]\d{1,2})}
CATEGORY_REGEX =
%r{\[timecategory:(.*)\]}

Instance Method Summary collapse

Constructor Details

#initialize(spend_command_arg, timezone) ⇒ SpendTimeAndDateSeparator

Returns a new instance of SpendTimeAndDateSeparator.



17
18
19
20
# File 'lib/gitlab/quick_actions/spend_time_and_date_separator.rb', line 17

def initialize(spend_command_arg, timezone)
  @spend_arg = spend_command_arg
  @timezone = timezone || Time.zone.name
end

Instance Method Details

#executeObject



22
23
24
25
26
27
# File 'lib/gitlab/quick_actions/spend_time_and_date_separator.rb', line 22

def execute
  return if @spend_arg.blank?
  return if date_present? && !valid_date?

  [time_spent, spent_at, category]
end