Class: JCON::Types::SimpleType

Inherits:
Type
  • Object
show all
Defined in:
lib/jcon/types.rb,
lib/jcon/conformance.rb

Instance Attribute Summary collapse

Attributes inherited from Type

#context

Instance Method Summary collapse

Methods inherited from Type

#inspect

Constructor Details

#initialize(name, &block) ⇒ SimpleType

Returns a new instance of SimpleType.



19
20
21
22
23
# File 'lib/jcon/types.rb', line 19

def initialize(name, &block)
  name = name.intern if name.is_a?(String)
  @name = name
  @test = block
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/jcon/types.rb', line 18

def name
  @name
end

Instance Method Details

#contains?(value) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'lib/jcon/conformance.rb', line 4

def contains?(value)
  if not @test and context and@context[name]
    return context[name].contains?(value)
  end
  raise "No definition for #{self}" unless @test
  @test.call(value)
end

#to_sObject



25
# File 'lib/jcon/types.rb', line 25

def to_s; name.to_s; end