Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rxsd/builtin_types.rb

Direct Known Subclasses

Char

Class Method Summary collapse

Instance Method Summary collapse

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_bObject

Convert string to boolean

Raises:

  • (ArgumentError)


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