class Fable::StringValue
Attributes
is_inline_whitespace[RW]
is_inline_whitespace?[RW]
is_newline[RW]
is_newline?[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Fable::Value::new
# File lib/fable/value.rb, line 144 def initialize(*args) if args.size == 1 self.initialize_with_string(args[0]) else super("") end end
Public Instance Methods
cast(new_type)
click to toggle source
# File lib/fable/value.rb, line 167 def cast(new_type) if new_type == self.class return self end if new_type == IntValue begin return IntValue.new(Integer(self.value)) rescue ArgumentError => e return nil end end if new_type == FloatValue begin return FloatValue.new(Float(self.value)) rescue ArgumentError => e return nil end end raise bad_cast_exception(new_type) end
initialize_with_string(value)
click to toggle source
# File lib/fable/value.rb, line 152 def initialize_with_string(value) #classify whitespace status self.is_newline = (value == "\n") self.is_inline_whitespace = true value.each_char do |character| if character != ' ' && character != "\t" self.is_inline_whitespace = false break end end self.value = value end
is_nonwhitespace?()
click to toggle source
# File lib/fable/value.rb, line 140 def is_nonwhitespace? return !is_newline? && !is_inline_whitespace? end
truthy?()
click to toggle source
# File lib/fable/value.rb, line 136 def truthy? return value.length > 0 end
value_type()
click to toggle source
# File lib/fable/value.rb, line 132 def value_type return OrderedValueTypes[StringValue] end