Class: CSVPlusPlus::Entities::Boolean

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

Overview

A boolean value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Boolean

Returns a new instance of Boolean.

Parameters:

  • value (::String, boolean)


17
18
19
20
21
# File 'lib/csv_plus_plus/entities/boolean.rb', line 17

def initialize(value)
  super()
  # TODO: probably can do a lot better in general on type validation
  @value = ::T.let(value.is_a?(::String) ? (value.downcase == 'true') : value, ::T::Boolean)
end

Instance Attribute Details

#valuetrue, false (readonly)

Returns the current value of value.

Returns:

  • (true, false)

    the current value of value



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

def value
  @value
end

Instance Method Details

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

Parameters:

Returns:

  • (::T::Boolean)


37
38
39
40
41
42
43
44
# File 'lib/csv_plus_plus/entities/boolean.rb', line 37

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

#evaluate(_position) ⇒ ::String

Parameters:

  • _position (Position)

Returns:

  • (::String)


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

def evaluate(_position)
  @value.to_s.upcase
end