class Tainbox::TypeConverter

Attributes

options[R]
type[R]
value[R]

Public Class Methods

conversion_method_name_for(type) click to toggle source
# File lib/tainbox/type_converter.rb, line 11
def self.conversion_method_name_for(type)
  "convert_to_#{type.to_s.downcase}".to_sym
end
define_converter(type, block) click to toggle source
# File lib/tainbox/type_converter.rb, line 5
def self.define_converter(type, block)
  method_name = conversion_method_name_for(type)
  raise "Converter for #{type} already exists" if instance_methods.include?(method_name)
  define_method(method_name, block)
end
new(type, value, options: {}) click to toggle source
# File lib/tainbox/type_converter.rb, line 15
def initialize(type, value, options: {})
  @type = type
  @value = value
  @options = options
end

Public Instance Methods

convert() click to toggle source
# File lib/tainbox/type_converter.rb, line 21
def convert
  method_name = self.class.conversion_method_name_for(type)
  raise "Type not supported: #{type}" unless respond_to?(method_name)
  send(method_name)
end