Class: TSJSON::ScalarType

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

Direct Known Subclasses

AnyType, BooleanType, FloatType, IntType, NullType, StringType

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(name) ⇒ ScalarType

Returns a new instance of ScalarType.



7
8
9
10
# File 'lib/types/scalar.rb', line 7

def initialize(name)
  super()
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#to_sObject



20
21
22
# File 'lib/types/scalar.rb', line 20

def to_s
  @name
end

#validate(value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/types/scalar.rb', line 12

def validate(value)
  raise ScalarValidationError.new(
          expected_type: @name,
          received_type: value.class.name,
          received_value: value
        )
end