Class: CSVPlusPlus::Entities::Number

Inherits:
Entity
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/entities/number.rb

Overview

A number value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Number

Returns a new instance of Number.

Parameters:

  • value (String, Numeric)

    Either a String that looks like a number, or an already parsed Numeric



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/csv_plus_plus/entities/number.rb', line 17

def initialize(value)
  super()

  @value =
    ::T.let(
      (if value.is_a?(::String)
         value.include?('.') ? Float(value) : Integer(value, 10)
       else
         value
       end),
      ::Numeric
    )
end

Instance Attribute Details

#valueNumeric (readonly)

The parsed number value

Returns:

  • (Numeric)

    the current value of value



9
10
11
# File 'lib/csv_plus_plus/entities/number.rb', line 9

def value
  @value
end

Instance Method Details

#==(other) ⇒ ::T::Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (::T::Boolean)


43
44
45
46
47
48
49
50
# File 'lib/csv_plus_plus/entities/number.rb', line 43

def ==(other)
  case other
  when self.class
    @value == other.value
  else
    false
  end
end

#evaluate(_position) ⇒ ::String

Parameters:

  • _position (Position)

Returns:

  • (::String)


35
36
37
# File 'lib/csv_plus_plus/entities/number.rb', line 35

def evaluate(_position)
  @value.to_s
end