Class: GovukSchemas::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_schemas/example.rb

Class Method Summary collapse

Class Method Details

.find(schema_name, example_name:) ⇒ Hash

Find an example by name



19
20
21
22
23
# File 'lib/govuk_schemas/example.rb', line 19

def self.find(schema_name, example_name:)
  path = "/formats/#{schema_name}/frontend/examples/#{example_name}.json"
  json = File.read("#{GovukSchemas::CONTENT_SCHEMA_DIR}#{path}")
  JSON.parse(json)
end

.find_all(schema_name) ⇒ Array

Find all examples for a schema



7
8
9
10
11
12
# File 'lib/govuk_schemas/example.rb', line 7

def self.find_all(schema_name)
  Dir.glob("#{GovukSchemas::CONTENT_SCHEMA_DIR}/formats/#{schema_name}/frontend/examples/*.json").map do |filename|
    json = File.read(filename)
    JSON.parse(json)
  end
end