Class: Types::RplBoolean

Inherits:
Object
  • Object
show all
Defined in:
lib/rpl/types/boolean.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ RplBoolean

Returns a new instance of RplBoolean.

Raises:



7
8
9
10
11
12
13
14
15
# File 'lib/rpl/types/boolean.rb', line 7

def initialize( value )
  raise RplTypeError unless self.class.can_parse?( value )

  @value = if value.is_a?( String )
             value.downcase == 'true'
           else
             value
           end
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/rpl/types/boolean.rb', line 5

def value
  @value
end

Class Method Details

.can_parse?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/rpl/types/boolean.rb', line 21

def self.can_parse?( value )
  return %w[true false].include?( value.downcase ) if value.is_a?( String )

  %w[TrueClass FalseClass].include?( value.class.to_s )
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
30
# File 'lib/rpl/types/boolean.rb', line 27

def ==( other )
  other.class == RplBoolean and
    other.value == value
end

#to_sObject



17
18
19
# File 'lib/rpl/types/boolean.rb', line 17

def to_s
  @value.to_s
end