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

#namespace, #namespace_lookup, #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.



38
39
40
41
42
43
44
# File 'lib/ctioga2/metabuilder/types/generic.rb', line 38

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



46
47
48
# File 'lib/ctioga2/metabuilder/types/generic.rb', line 46

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

#type_nameObject



33
34
35
# File 'lib/ctioga2/metabuilder/types/generic.rb', line 33

def type_name
  return 'function_based'
end

#type_to_string_internal(val) ⇒ Object



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

def type_to_string_internal(val)
  return val.to_s
end