Class: MobyUtil::StringHelper
- Defined in:
- lib/tdriver/util/common/string.rb
Class Method Summary collapse
-
.boolean?(string) ⇒ Boolean
- Function determines if string is “true” or “false” == params string
-
String == returns TrueClass/FalseClass.
-
.numeric?(string) ⇒ Boolean
- Function determines if string is numeric == params string
-
Numeric string == returns TrueClass/FalseClass.
-
.to_boolean(string) ⇒ Object
- Function converts “true” or “false” to boolean == params string
-
String == returns TrueClass/FalseClass.
Class Method Details
.boolean?(string) ⇒ Boolean
Function determines if string is “true” or “false”
params
- string
-
String
returns
TrueClass/FalseClass
126 127 128 129 130 131 132 133 |
# File 'lib/tdriver/util/common/string.rb', line 126 def self.boolean?( string ) # raise exception if argument type other than String string.check_type( String, "Wrong argument type $1 (Expected $2)" ) /^(true|false)$/i.match( string ).kind_of?( MatchData ) end |
.numeric?(string) ⇒ Boolean
Function determines if string is numeric
params
- string
-
Numeric string
returns
TrueClass/FalseClass
140 141 142 143 144 145 146 147 148 |
# File 'lib/tdriver/util/common/string.rb', line 140 def self.numeric?( string ) # raise exception if argument type other than String string.check_type String, 'Wrong argument type $1 (expected: $2)' /^[0-9]+$/.match( string ).kind_of?( MatchData ) end |
.to_boolean(string) ⇒ Object
Function converts “true” or “false” to boolean
params
- string
-
String
returns
TrueClass/FalseClass
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/tdriver/util/common/string.rb', line 155 def self.to_boolean( string ) if MobyUtil::StringHelper::boolean?( string ) /true/i.match( string ).kind_of?( MatchData ) else raise ArgumentError.new("Invalid value #{ string.inspect } for boolean (expected: \"true\" or \"false\")" ) end end |