1
# generic.rb: conversion-function based type (or the Death of MetaBuilder)
2
# you can choose among several possibilities
3
# Copyright (C) 2010 Vincent Fourmond
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
require 'ctioga2/utils'
23
Version::register_svn_info('$Revision$', '$Date$')
30
# A type based on a conversion function from_text from a given
32
class FunctionBasedType < Type
34
type_name :function_based
37
return 'function_based'
43
raise "type must have a :class key" unless type.has_key?(:class)
44
# We make a copy for our own purposes.
46
@func_name = type[:func_name] || :from_text
49
def string_to_type_internal(str)
50
return @cls.send(@func_name, str)
53
def type_to_string_internal(val)