Class: JSON::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/json-schema/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, uri) ⇒ Schema

Returns a new instance of Schema.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/json-schema/schema.rb', line 10

def initialize(schema,uri)
  @schema = schema
  @uri = uri
  
  # If there is an ID on this schema, use it to generate the URI
  if @schema['id']
    temp_uri = URI.parse(@schema['id'])
    if temp_uri.relative?
      uri.path = (Pathname.new(uri.path).parent + @schema['id']).cleanpath
      temp_uri = uri
    end
    @uri = temp_uri
  end
  @uri.fragment = nil
end

Instance Attribute Details

#schemaObject

Returns the value of attribute schema.



8
9
10
# File 'lib/json-schema/schema.rb', line 8

def schema
  @schema
end

#uriObject

Returns the value of attribute uri.



8
9
10
# File 'lib/json-schema/schema.rb', line 8

def uri
  @uri
end

Instance Method Details

#base_uriObject



26
27
28
29
30
# File 'lib/json-schema/schema.rb', line 26

def base_uri
  parts = @uri.to_s.split('/')
  parts.pop
  parts.join('/') + '/'
end

#to_sObject



32
33
34
# File 'lib/json-schema/schema.rb', line 32

def to_s
  @schema.to_json
end