Class: Hocon::Impl::ConfigNumber

Inherits:
Object
  • Object
show all
Includes:
AbstractConfigValue
Defined in:
lib/hocon/impl/config_number.rb

Direct Known Subclasses

ConfigDouble, ConfigInt

Constant Summary

Constants included from AbstractConfigValue

AbstractConfigValue::ConfigBugOrBrokenError, AbstractConfigValue::ConfigImplUtil, AbstractConfigValue::ResolveStatus

Instance Attribute Summary collapse

Attributes included from AbstractConfigValue

#origin

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractConfigValue

#at_key, #at_key_with_origin, #at_path, #at_path_with_origin, #construct_delayed_merge, #delay_merge, has_descendant_in_list?, #ignores_fallbacks?, indent, #inspect, #merged_stack_with_non_object, #merged_stack_with_object, #merged_stack_with_the_unmergeable, #merged_with_non_object, #merged_with_object, #merged_with_the_unmergeable, #new_copy, #relativized, #render, #render_to_sb, #render_value_to_sb, replace_child_in_list, #require_not_ignoring_fallbacks, #resolve_status, #resolve_substitutions, #to_fallback_value, #to_s, #with_fallback, #with_fallbacks_ignored, #with_origin

Methods included from ConfigValue

#at_key, #at_path, #origin, #render, #unwrapped, #value_type, #with_fallback, #with_origin

Methods included from ConfigMergeable

#with_fallback

Constructor Details

#initialize(origin, original_text) ⇒ ConfigNumber

Returns a new instance of ConfigNumber.



22
23
24
25
# File 'lib/hocon/impl/config_number.rb', line 22

def initialize(origin, original_text)
  super(origin)
  @original_text = original_text
end

Instance Attribute Details

#original_textObject (readonly)

Returns the value of attribute original_text.



26
27
28
# File 'lib/hocon/impl/config_number.rb', line 26

def original_text
  @original_text
end

Class Method Details

.new_number(origin, number, original_text) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/hocon/impl/config_number.rb', line 13

def self.new_number(origin, number, original_text)
  as_int = number.to_i
  if as_int == number
    Hocon::Impl::ConfigInt.new(origin, as_int, original_text)
  else
    Hocon::Impl::ConfigDouble.new(origin, number, original_text)
  end
end

Instance Method Details

#==(other) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/hocon/impl/config_number.rb', line 46

def ==(other)
  if other.is_a?(Hocon::Impl::ConfigNumber) && can_equal(other)
    @value == other.value
  else
    false
  end
end

#can_equal(other) ⇒ Object



42
43
44
# File 'lib/hocon/impl/config_number.rb', line 42

def can_equal(other)
  other.is_a?(Hocon::Impl::ConfigNumber)
end

#hashObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hocon/impl/config_number.rb', line 54

def hash
  # This hash function makes it so that a ConfigNumber with a 3.0
  # and one with a 3 will return the hash code
  to_int = @value.round

  # If the value is an integer or a floating point equal to an integer
  if to_int == @value
    to_int.hash
  else
    @value.hash
  end
end

#int_value_range_checked(path) ⇒ Object



32
33
34
35
36
# File 'lib/hocon/impl/config_number.rb', line 32

def int_value_range_checked(path)
  # We don't need to do any range checking here due to the way Ruby handles
  # integers (doesn't have the 32-bit/64-bit distinction that Java does).
  long_value
end

#long_valueObject



38
39
40
# File 'lib/hocon/impl/config_number.rb', line 38

def long_value
  raise "long_value needs to be overriden by sub-classes of #{Hocon::Impl::ConfigNumber}, in this case #{self.class}"
end

#transform_to_stringObject



28
29
30
# File 'lib/hocon/impl/config_number.rb', line 28

def transform_to_string
  @original_text
end