Class: ParameterSubstitution::Formatters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/parameter_substitution/formatters/base.rb

Class Method Summary collapse

Class Method Details

.descriptionObject

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/parameter_substitution/formatters/base.rb', line 7

def description
  raise NotImplementedError, "Derived classes must implement"
end

.encodingObject



25
26
27
# File 'lib/parameter_substitution/formatters/base.rb', line 25

def encoding
  :raw
end

.format(_value) ⇒ Object

Raises:

  • (NotImplementedError)


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.

Returns:

  • (Boolean)


21
22
23
# File 'lib/parameter_substitution/formatters/base.rb', line 21

def has_parameters?
  false
end

.keyObject



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