Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rxsd/builtin_types.rb
Direct Known Subclasses
Class Method Summary collapse
-
.from_s(str) ⇒ Object
Convert string to string (just return str).
Instance Method Summary collapse
-
#to_b ⇒ Object
Convert string to boolean.
-
#to_xa(args = {}) ⇒ Object
Helper to convert string to array of specified type.
Class Method Details
.from_s(str) ⇒ Object
Convert string to string (just return str)
39 40 41 |
# File 'lib/rxsd/builtin_types.rb', line 39 def self.from_s(str) str end |
Instance Method Details
#to_b ⇒ Object
Convert string to boolean
32 33 34 35 36 |
# File 'lib/rxsd/builtin_types.rb', line 32 def to_b return true if self == true || self =~ /^true$/i return false if self == false || self.nil? || self =~ /^false$/i raise ArgumentError, "invalid value for Boolean: \"#{self}\"" end |
#to_xa(args = {}) ⇒ Object
Helper to convert string to array of specified type.
44 45 46 47 48 49 50 |
# File 'lib/rxsd/builtin_types.rb', line 44 def to_xa(args = {}) arr = [] item_type = args[:type] delim = args.has_key?(:delim) ? args[:delim] : ' ' split(delim).collect { |item| arr.push(item_type.from_s(item)) } return arr end |