class GovukSchemas::Example
def self.examples_path(schema_name)
-
(String)
- the path to use for examples
Parameters:
-
schema_name
(String
) -- like "detailed_guide", "policy" or "publication"
def self.examples_path(schema_name) examples_dir = "#{GovukSchemas.content_schema_dir}/examples" if Dir.exist?(examples_dir) "#{examples_dir}/#{schema_name}/frontend" else "#{GovukSchemas.content_schema_dir}/formats/#{schema_name}/frontend/examples" end end
def self.find(schema_name, example_name:)
-
(Hash)
- the example content item
Parameters:
-
example_name
(String
) -- the name of the example JSON file -
schema_name
(String
) -- like "detailed_guide", "policy" or "publication"
def self.find(schema_name, example_name:) json = File.read("#{examples_path(schema_name)}/#{example_name}.json") JSON.parse(json) end
def self.find_all(schema_name)
-
(Array)
- array of example content items
Parameters:
-
schema_name
(String
) -- like "detailed_guide", "policy" or "publication"
def self.find_all(schema_name) Dir.glob("#{examples_path(schema_name)}/*.json").map do |filename| json = File.read(filename) JSON.parse(json) end end