Class: Fable::Value

Inherits:
RuntimeObject show all
Defined in:
lib/fable/value.rb

Instance Attribute Summary collapse

Attributes inherited from RuntimeObject

#original_object, #own_debug_metadata, #parent, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RuntimeObject

#compact_path_string, #convert_path_to_relative, #debug_line_number_of_path, #debug_metadata, #indentation_string, #resolve_path, #root_content_container

Constructor Details

#initialize(value) ⇒ Value

Returns a new instance of Value.



8
9
10
11
# File 'lib/fable/value.rb', line 8

def initialize(value)
  super()
  self.value_object = value
end

Instance Attribute Details

#value_objectObject Also known as: value

Returns the value of attribute value_object.



3
4
5
# File 'lib/fable/value.rb', line 3

def value_object
  @value_object
end

Class Method Details

.create(value) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fable/value.rb', line 29

def self.create(value)
  case value
  when TrueClass, FalseClass
    converted_to_int = value ? 1 : 0
    return IntValue.new(converted_to_int)
  when Integer
    return IntValue.new(value)
  when Numeric
    return FloatValue.new(value.to_f)
  when String
    return StringValue.new(value)
  when Path
    return DivertTargetValue.new(value)
  when InkList
    return ListValue.new(value)
  else
    return nil
  end
end

Instance Method Details

#bad_cast_exception(target_type) ⇒ Object



53
54
55
# File 'lib/fable/value.rb', line 53

def bad_cast_exception(target_type)
  return StoryError.new("Can't cast #{self.value_object} from #{OrderedValueTypes.key(self.value_type)} to #{target_type}")
end

#cast(new_type) ⇒ Object

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/fable/value.rb', line 21

def cast(new_type)
  raise NotImplementedError
end

#copyObject



49
50
51
# File 'lib/fable/value.rb', line 49

def copy
  return self.class.create(value_object)
end

#to_sObject



25
26
27
# File 'lib/fable/value.rb', line 25

def to_s
  value_object.to_s
end

#truthy?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/fable/value.rb', line 17

def truthy?
  raise NotImplementedError
end

#value_typeObject

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/fable/value.rb', line 13

def value_type
  raise NotImplementedError
end