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})}

Instance Method Summary collapse

Constructor Details

#initialize(spend_command_arg) ⇒ SpendTimeAndDateSeparator

Returns a new instance of SpendTimeAndDateSeparator.



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

def initialize(spend_command_arg)
  @spend_arg = spend_command_arg
end

Instance Method Details

#executeObject



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

def execute
  return if @spend_arg.blank?
  return [get_time, DateTime.current] unless date_present?
  return unless valid_date?

  [get_time, get_date]
end