Class: Types::RplBoolean
- Inherits:
-
Object
- Object
- Types::RplBoolean
- Defined in:
- lib/rpl/types/boolean.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value) ⇒ RplBoolean
constructor
A new instance of RplBoolean.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ RplBoolean
Returns a new instance of RplBoolean.
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
#value ⇒ Object
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
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 && other.value == value end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/rpl/types/boolean.rb', line 17 def to_s @value.to_s end |