Module: L43::Time::Parser
- Includes:
- Ts
- Included in:
- Delta, Duration
- Defined in:
- lib/l43/time/parser.rb
Defined Under Namespace
Modules: Helper
Constant Summary
collapse
- Prefix =
%r{
(?<unit>[[:lower:]]+) [[:space:]]*:[[:space:]]* (?<value>[[:digit:]]+ (?:\.[[:digit:]]+)? )
}x
- Suffix =
%r{
(?<value>[[:digit:]]+ (?:\.[[:digit:]]+)?) [[:space:]]* (?<unit>[[:lower:]]+)
}x
Constants included
from Ts
Ts::DecimalPart, Ts::Seperators
Instance Method Summary
collapse
Methods included from Ts
#duration_as_string, #duration_as_string!
Instance Method Details
#parse_duration(str) ⇒ Object
#parse_duration!(str) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/l43/time/parser.rb', line 32
def parse_duration!(str)
case parse_duration(str)
in :ok, value
value
in :error, msg
raise BadFormat, msg
end
end
|
#parse_or_duration(str) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/l43/time/parser.rb', line 58
def parse_or_duration(str)
case duration_as_string(str)
in :ok, value
[:ok, value]
else
parse_duration(str)
end
end
|
#parse_or_duration!(str) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/l43/time/parser.rb', line 49
def parse_or_duration!(str)
case parse_or_duration(str)
in :ok, value
value
in :error, msg
raise BadFormat, msg
end
end
|