class KwalifyToJsonSchema::Options
The possible options for the conversion and the associated accessors
Constants
- DECLARATION
Converter
options: | Name | Type | Default value| Description | |———————–|——–|————–|——————————————————————————————| | :id | string | nil | The JSON schema identifier | | :title | string | nil | The JSON schema title | | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present| | :issues_to_description| boolean| false | To append the issues to the JSON schema description | | :issues_to_stderr | boolean| false | To write the issues to standard error output | | :custom_processing | object | nil | To customize the conversion | | :schema_version | string | “draft-04” | JSON schema version. Changing this value only change the value of $schema field | | :verbose | boolean| false | To be verbose when converting | –
Attributes
The options as Hash
Public Class Methods
Get description for option name
# File lib/kwalify_to_json_schema/options.rb, line 88 def self.cli_option(name) o = parse_hash[name] [o[:name], :type => o[:type].to_sym, :default => o[:default_value], :desc => o[:description]] end
# File lib/kwalify_to_json_schema/options.rb, line 30 def initialize(options) @options_hash = options.is_a?(Options) ? options.options_hash : options end
Parse options declaration text and give an array of Hash
# File lib/kwalify_to_json_schema/options.rb, line 39 def self.parse DECLARATION.lines.map { |l| next nil if l.strip.empty? # Parse line const_name, comment = l.split("#", 2).map(&:strip) name = const_name.downcase.to_s description = comment.split("[").first.strip # Get type and default value m = comment.match(/\[(.+)\].*\((.+)\)/) type, default_value = m.captures default_value = eval(default_value) # Create read accessor attr_reader_name = "#{name}#{type == "boolean" ? "?" : ""}" # Array entry as Hash for the option { const_name: const_name, const_name_full: "#{Options.name}::#{const_name}", name: name.to_sym, description: description, type: type, default_value: default_value, attr_reader_name: attr_reader_name, } }.compact end
Same as :parse but give a Hash with the name as key
# File lib/kwalify_to_json_schema/options.rb, line 69 def self.parse_hash parse.map { |e| [e[:name], e] }.to_h end
Setup the constants and methods for the options Example: ID will lead to get ID constant and :id method
# File lib/kwalify_to_json_schema/options.rb, line 75 def self.setup parse.each { |o| # Create constant const_set o[:const_name], o[:name] # Create read accessor define_method(o[:attr_reader_name]) { options_hash[o[:name]] || o[:default_value] } } end
Public Instance Methods
# File lib/kwalify_to_json_schema/options.rb, line 34 def to_s YAML.dump("Options" => options_hash) end