Module: StoreHours

Defined in:
lib/store_hours.rb,
lib/store_hours/version.rb,
lib/store_hours/constants.rb,
lib/store_hours/common_methods.rb,
lib/store_hours/semantic_error.rb,
lib/store_hours/tree_transformer.rb,
lib/store_hours/text_input_parser.rb

Defined Under Namespace

Classes: SemanticError, StoreHours, TextInputParser, TreeTransformer

Constant Summary collapse

VERSION =
"0.0.2"
WEEKDAY_TO_NUM =
{ :mon => 1, :tue => 2, :wed => 3, :thu => 4, :fri => 5, :sat => 6, :sun => 7}
NUM_TO_WEEKDAY =
{ 1=> :Mon, 2 => :Tue, 3 => :Wed, 4 => :Thu, 5 => :Fri, 6 => :Sat, 7 => :Sun }

Class Method Summary collapse

Class Method Details

.convert_time_input_to_minutes(hour, minutes, am_or_pm) ⇒ Fixnum

Convert a time point in a day to the number of minutes passed since midnight.

Parameters:

  • hour (Fixnum)

    the hour component of time (not in military format)

  • minutes (Fixnum)

    the minutes component of time

  • am_or_pm (Symbol, :am or :pm)

    morning or afternoon

Returns:

  • (Fixnum)

    the number of minutes passed since midnight



9
10
11
12
13
14
# File 'lib/store_hours/common_methods.rb', line 9

def self.convert_time_input_to_minutes(hour, minutes, am_or_pm)
  hour += 12 if am_or_pm == :pm and hour < 12
  hour = 0 if am_or_pm == :am and hour == 12

  hour * 60 + minutes
end

.from_minutes_to_time_str(t) ⇒ String

This is the reverse function of convert_time_input_to_minutes(hour, minutes, am_or_pm).

This function coverts the number of minutes passed since midnight to a standard time string like 10:00AM.

Parameters:

  • t (Fixnum)

    the number of minutes passed since midnight

Returns:

  • (String)

    the standard time string



24
25
26
27
28
29
30
31
32
# File 'lib/store_hours/common_methods.rb', line 24

def self.from_minutes_to_time_str(t)
  hour_part = t / 60
  minute_part = t % 60

  am_or_pm = (hour_part >= 12 ? 'PM' : 'AM')
  hour_part = hour_part - 12 if hour_part >= 13

  "#{ hour_part }:#{ format('%02d', minute_part) }#{ am_or_pm }"
end