Class: TSJSON::Literal

Inherits:
Base
  • Object
show all
Defined in:
lib/types/literal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#compile, #index, #property, #valid?

Constructor Details

#initialize(value) ⇒ Literal

Returns a new instance of Literal.



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

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/types/literal.rb', line 3

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



9
10
11
12
13
# File 'lib/types/literal.rb', line 9

def ==(other)
  return value == other unless other.is_a?(self.class)

  value == other.value
end

#validate(other) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/types/literal.rb', line 15

def validate(other)
  unless @value == other
    raise LiteralValidationError.new(
            expected_value: @value, received_value: other
          )
  end

  true
end