class ConfigNumber

Attributes

original_text[R]

Public Class Methods

new(origin, original_text) click to toggle source
Calls superclass method Hocon::Impl::AbstractConfigValue::new
# File lib/hocon/impl/config_number.rb, line 22
def initialize(origin, original_text)
  super(origin)
  @original_text = original_text
end
new_number(origin, number, original_text) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# 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) click to toggle source
# File lib/hocon/impl/config_number.rb, line 42
def can_equal(other)
  other.is_a?(Hocon::Impl::ConfigNumber)
end
hash() click to toggle source
# 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) click to toggle source
# 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_value() click to toggle source
# 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_string() click to toggle source
# File lib/hocon/impl/config_number.rb, line 28
def transform_to_string
  @original_text
end