Class: CTioga2::MetaBuilder::Types::FunctionBasedType

Inherits:
CTioga2::MetaBuilder::Type show all
Defined in:
lib/ctioga2/metabuilder/types/generic.rb

Overview

A type based on a conversion function from_text from a given class/module.

Instance Attribute Summary

Attributes inherited from CTioga2::MetaBuilder::Type

#passthrough, #re_shortcuts, #shortcuts, #type

Instance Method Summary collapse

Methods inherited from CTioga2::MetaBuilder::Type

#boolean?, #default_value, from_string, get_param_type, get_type, #option_parser_long_option, #option_parser_option, #string_to_type, type_name, #type_to_string

Constructor Details

#initialize(type) ⇒ FunctionBasedType

Returns a new instance of FunctionBasedType.



41
42
43
44
45
46
47
# File 'lib/ctioga2/metabuilder/types/generic.rb', line 41

def initialize(type)
  super
  raise "type must have a :class key" unless type.has_key?(:class)
  # We make a copy for our own purposes.
  @cls = type[:class]
  @func_name = type[:func_name] || :from_text
end

Instance Method Details

#string_to_type_internal(str) ⇒ Object



49
50
51
# File 'lib/ctioga2/metabuilder/types/generic.rb', line 49

def string_to_type_internal(str)
  return @cls.send(@func_name, str)
end

#type_nameObject



36
37
38
# File 'lib/ctioga2/metabuilder/types/generic.rb', line 36

def type_name
  return 'function_based'
end

#type_to_string_internal(val) ⇒ Object



53
54
55
# File 'lib/ctioga2/metabuilder/types/generic.rb', line 53

def type_to_string_internal(val)
  return val.to_s
end