Class: CSVPlusPlus::Entities::Boolean

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

Overview

A boolean value

Instance Attribute Summary collapse

Attributes inherited from Entity

#id, #type

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Boolean

Returns a new instance of Boolean.

Parameters:

  • value (::String, boolean)


15
16
17
18
19
# File 'lib/csv_plus_plus/entities/boolean.rb', line 15

def initialize(value)
  super(::CSVPlusPlus::Entities::Type::Boolean)
  # 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)


33
34
35
36
37
# File 'lib/csv_plus_plus/entities/boolean.rb', line 33

def ==(other)
  return false unless super

  other.is_a?(self.class) && value == other.value
end

#evaluate(_runtime) ⇒ ::String

Parameters:

Returns:

  • (::String)


25
26
27
# File 'lib/csv_plus_plus/entities/boolean.rb', line 25

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