Class: Runby::Utility::ParameterSanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/runby_pace/utility/parameter_sanitizer.rb

Overview

Helps sanitize method parameters. (See RSpec documentation for examples)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter) ⇒ ParameterSanitizer

Returns a new instance of ParameterSanitizer.


9
10
11
# File 'lib/runby_pace/utility/parameter_sanitizer.rb', line 9

def initialize(parameter)
  @parameter = parameter
end

Instance Attribute Details

#parameterObject (readonly)

Returns the value of attribute parameter


7
8
9
# File 'lib/runby_pace/utility/parameter_sanitizer.rb', line 7

def parameter
  @parameter
end

Class Method Details

.sanitize(parameter) ⇒ Object


13
14
15
# File 'lib/runby_pace/utility/parameter_sanitizer.rb', line 13

def self.sanitize(parameter)
  ParameterSanitizer.new parameter
end

Instance Method Details

#as(type) ⇒ Object


17
18
19
20
21
# File 'lib/runby_pace/utility/parameter_sanitizer.rb', line 17

def as(type)
  return @parameter if @parameter.is_a?(type)
  raise "Unable to sanitize parameter of type #{type}. Missing 'parse' method." unless type.respond_to? :parse
  type.parse(@parameter)
end