Class: ParameterSubstitution::Formatters::Base
- Inherits:
-
Object
- Object
- ParameterSubstitution::Formatters::Base
show all
- Defined in:
- lib/parameter_substitution/formatters/base.rb
Direct Known Subclasses
AddPrefix, BlankIfNil, CgiUnescape, DateTimeFormat, Downcase, DurationAsSeconds, DurationAsTime, DurationGroupedByDescription, GreaterThanValue, HexToBase64, IfNil, IfTruthy, JsonParse, Left, Lookup, Lower, Md5, Mid, Right, Sha256, SplitAfterColon, SplitAndFind, SplitBeforeColon, StringToBase64, Trim, Upper
Class Method Summary
collapse
Class Method Details
.description ⇒ Object
7
8
9
|
# File 'lib/parameter_substitution/formatters/base.rb', line 7
def description
raise NotImplementedError, "Derived classes must implement"
end
|
.encoding ⇒ Object
25
26
27
|
# File 'lib/parameter_substitution/formatters/base.rb', line 25
def encoding
:raw
end
|
11
12
13
|
# File 'lib/parameter_substitution/formatters/base.rb', line 11
def format(_value)
raise NotImplementedError, "Derived classes must implement"
end
|
.has_parameters? ⇒ Boolean
Formats that have parameters are constructed and format is called on the instance. Formats without parameters have format called on the class.
21
22
23
|
# File 'lib/parameter_substitution/formatters/base.rb', line 21
def has_parameters?
false
end
|
.key ⇒ Object
15
16
17
|
# File 'lib/parameter_substitution/formatters/base.rb', line 15
def key
name.split('::').last.gsub(/Format/, '').underscore
end
|
.parse_duration(duration) ⇒ Object
TODO: Move out of the base class.
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/parameter_substitution/formatters/base.rb', line 30
def parse_duration(duration)
if duration.is_a?(String)
if duration =~ /([\d]{1,2})\:([\d]{1,2})\:([\d]{1,2})/
(Regexp.last_match(1).to_i.hours + Regexp.last_match(2).to_i.minutes + Regexp.last_match(3).to_i.seconds).to_i
elsif duration =~ /([\d]{1,2})\:([\d]{1,2})/
(Regexp.last_match(1).to_i.minutes + Regexp.last_match(2).to_i.seconds).to_i
else
duration.to_i
end
else
duration.to_i
end
end
|