Class: BBFS::Params::Param
- Inherits:
-
Object
- Object
- BBFS::Params::Param
- Defined in:
- lib/params.rb
Overview
Represents a parameter.
Instance Attribute Summary collapse
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name, value, type, desc) ⇒ Param
constructor
supported types are: String, Integer, Float and Boolean.
-
#value_type_check(value) ⇒ Object
value_type_check method: 1.
Constructor Details
#initialize(name, value, type, desc) ⇒ Param
supported types are: String, Integer, Float and Boolean
129 130 131 132 133 134 |
# File 'lib/params.rb', line 129 def initialize(name, value, type, desc) @name = name @type = type @desc = desc @value = value_type_check value end |
Instance Attribute Details
#desc ⇒ Object
Returns the value of attribute desc.
71 72 73 |
# File 'lib/params.rb', line 71 def desc @desc end |
#name ⇒ Object
Returns the value of attribute name.
69 70 71 |
# File 'lib/params.rb', line 69 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
72 73 74 |
# File 'lib/params.rb', line 72 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
70 71 72 |
# File 'lib/params.rb', line 70 def value @value end |
Instance Method Details
#value_type_check(value) ⇒ Object
value_type_check method:
-
Check if member:‘type’ is one of:Integer, Float, String or Boolean.
-
input parameter:‘value’ class type is valid to override this parameter.
-
Return value. The value to override with correct type. A cast from integer to Float will be made for Float parameters which are set with integer values.
-
Check will be skipped for nil value.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/params.rb', line 80 def value_type_check(value) if value.nil? return value end case( @type ) when 'Integer' then if not @value.nil? if not ((value.class.eql? Integer) or (value.class.eql? Fixnum)) raise "Parameter:'#{@name}' type:'Integer' but value type to override " \ "is:'#{value.class}'." end end when 'Float' then if not @value.nil? if not value.class.eql? Float if not ((value.class.eql? Integer) or (value.class.eql? Fixnum)) raise("Parameter:'#{@name}' type:'Float' but value type to override " \ "is:'#{value.class}'.") else return value.to_f end end end when 'String' then if not @value.nil? if not value.class.eql? String raise("Parameter:'#{@name}' type:'String' but value type to override " \ "is:'#{value.class}'.") end end when 'Boolean' then if not @value.nil? if not((value.class.eql? TrueClass) or (value.class.eql? FalseClass)) raise("Parameter:'#{@name}' type:'Boolean' but value type to override " \ "is:'#{value.class}'.") end end else raise("Parameter:'#{@name}' type:'#{@value.class}' but parameter " \ "type to override:'#{value.class}' is not supported. " + \ "Supported types are:Integer, Float, String or Boolean.") end return value end |