1
# numbers.rb : Different Types to deal with numbers
2
# Copyright (C) 2006 Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
require 'ctioga2/utils'
23
Version::register_svn_info('$Revision: 2 $', '$Date: 2009-04-25 14:03:30 +0200 (Sat, 25 Apr 2009) $')
27
# The module Types should be used for all subclasses of
28
# Type, to keep the place clean and tidy.
32
class IntegerParameter < Type
34
type_name :integer, 'number', 0
36
def string_to_type_internal(str)
43
class FloatParameter < Type
45
type_name :float, 'number', 0.0
47
def string_to_type_internal(str)
54
class FloatRangeParameter < Type
56
RANGE_RE = /([^:]+):([^:]+)/
58
type_name :float_range, 'range'
60
def string_to_type_internal(str)
61
raise IncorrectInput, "#{str} is not a valid range" unless
63
s,e = Float($1), Float($2)
67
def type_to_string_internal(value)
68
return "#{value.first.to_s}:#{value.last.to_s}"
73
# Returns a [ start, end ] array where elements are either Float
75
class PartialFloatRangeType < Type
77
RANGE_RE = /([^:]+)?:([^:]+)?/
79
type_name :partial_float_range, 'range'
81
def string_to_type_internal(str)
82
raise IncorrectInput, "#{str} is not a valid range" unless
84
s,e = ($1 ? Float($1) : nil), ($2 ? Float($2) : nil)
88
def type_to_string_internal(value)
89
return "#{value.first.to_s}:#{value.last.to_s}"