Class: L43::Time::TimeCalc::ArgParser

Inherits:
Object
  • Object
show all
Includes:
EnumerableExtension
Defined in:
lib/l43/time/time_calc/arg_parser.rb

Constant Summary collapse

MethodNames =
%w[ 
  midnight 
  tomorrow
  yesterday
].freeze
MethodLiterals =
MethodNames.map { ".#{it}" }.freeze
SecsPerUnit =
{
  "s" => 1,
  "m" => 60,
  "h" => 3600,
  "d" => 86400,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EnumerableExtension

#find_value

Instance Attribute Details

#now ⇒ Object (readonly)

Returns the value of attribute now.



28
29
30
# File 'lib/l43/time/time_calc/arg_parser.rb', line 28

def now
  @now
end

Instance Method Details

#parse(args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/l43/time/time_calc/arg_parser.rb', line 30

def parse(args)
  if args.empty?
    [:time, now]
  else
    case _time_expr_parser.parse(args.join(" "))
    in nil
      [:error, "bad format"] 
    in ast, ""
      ast
      # TODO:
    in [:time, time], rest
      _parse_methods(time, rest)
    in _, rest
      [:error, "unexpected suffix #{rest.inspect}"]
    end
  end
end