Class: Fable::StringValue
- Inherits:
-
Value
- Object
- RuntimeObject
- Value
- Fable::StringValue
- Defined in:
- lib/fable/value.rb
Instance Attribute Summary collapse
-
#is_inline_whitespace ⇒ Object
(also: #is_inline_whitespace?)
Returns the value of attribute is_inline_whitespace.
-
#is_newline ⇒ Object
(also: #is_newline?)
Returns the value of attribute is_newline.
Attributes inherited from Value
Attributes inherited from RuntimeObject
#original_object, #own_debug_metadata, #parent, #path
Instance Method Summary collapse
- #cast(new_type) ⇒ Object
-
#initialize(*args) ⇒ StringValue
constructor
A new instance of StringValue.
- #initialize_with_string(value) ⇒ Object
- #is_nonwhitespace? ⇒ Boolean
- #truthy? ⇒ Boolean
- #value_type ⇒ Object
Methods inherited from Value
#bad_cast_exception, #copy, create, #to_s
Methods inherited from RuntimeObject
#compact_path_string, #convert_path_to_relative, #copy, #debug_line_number_of_path, #debug_metadata, #indentation_string, #resolve_path, #root_content_container
Constructor Details
#initialize(*args) ⇒ StringValue
Returns a new instance of StringValue.
144 145 146 147 148 149 150 |
# File 'lib/fable/value.rb', line 144 def initialize(*args) if args.size == 1 self.initialize_with_string(args[0]) else super("") end end |
Instance Attribute Details
#is_inline_whitespace ⇒ Object Also known as: is_inline_whitespace?
Returns the value of attribute is_inline_whitespace.
127 128 129 |
# File 'lib/fable/value.rb', line 127 def is_inline_whitespace @is_inline_whitespace end |
#is_newline ⇒ Object Also known as: is_newline?
Returns the value of attribute is_newline.
127 128 129 |
# File 'lib/fable/value.rb', line 127 def is_newline @is_newline end |
Instance Method Details
#cast(new_type) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# 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) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# 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? ⇒ Boolean
140 141 142 |
# File 'lib/fable/value.rb', line 140 def is_nonwhitespace? return !is_newline? && !is_inline_whitespace? end |
#truthy? ⇒ Boolean
136 137 138 |
# File 'lib/fable/value.rb', line 136 def truthy? return value.length > 0 end |
#value_type ⇒ Object
132 133 134 |
# File 'lib/fable/value.rb', line 132 def value_type return OrderedValueTypes[StringValue] end |