Class: CSVPlusPlus::Entities::Number

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

Overview

A number value

Instance Attribute Summary collapse

Attributes inherited from Entity

#id, #type

Instance Method Summary collapse

Methods inherited from Entity

#method_missing, #respond_to_missing?

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



12
13
14
15
16
17
18
19
20
21
# File 'lib/csv_plus_plus/entities/number.rb', line 12

def initialize(value)
  super(:number)

  @value =
    if value.instance_of?(::String)
      value.include?('.') ? Float(value) : Integer(value, 10)
    else
      value
    end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CSVPlusPlus::Entities::Entity

Instance Attribute Details

#valueNumeric (readonly)

The parsed number value

Returns:

  • (Numeric)

    the current value of value



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

def value
  @value
end

Instance Method Details

#==(other) ⇒ boolean

Returns:

  • (boolean)


29
30
31
# File 'lib/csv_plus_plus/entities/number.rb', line 29

def ==(other)
  super && value == other.value
end

#to_sString

Returns:



24
25
26
# File 'lib/csv_plus_plus/entities/number.rb', line 24

def to_s
  @value.to_s
end