class RDF::CLI::Option
Option
description for use within Readers/Writers. See {RDF::Reader.options} and {RDF::Writer.options} for example usage.
Attributes
Associated HTML form control @return [:text, :textarea, :radio, :checkbox, :select, :url, :url2, :none]
Potential values (for select or radio) or Ruby datatype @return [Class, Array<String>]
Default value for this option @return [Object]
Description of this option (optional) @return [String]
Arguments passed to OptionParser#on @return [Array<String>]
Symbol used for this option when calling ‘Reader.new` @return [Symbol]
Use of this option @return [:optional, :disabled, :removed, :required]
Public Class Methods
Source
# File lib/rdf/cli.rb, line 143 def initialize(symbol: nil, on: nil, datatype: nil, control: nil, description: nil, use: :optional, default: nil, **options, &block) raise ArgumentError, "symbol is a required argument" unless symbol raise ArgumentError, "on is a required argument" unless on @symbol, @on, @datatype, @control, @description, @use, @default, @callback = symbol.to_sym, Array(on), datatype, control, description, use, default, block end
Create a new option with optional callback.
@param [Symbol] symbol @param [Array<String>] on @param [String] datatype @param [Object] default @param [String] control @param [String] description @param [[:optional, :disabled, :removed, :required]] use @yield value which may be used within ‘OptionParser#on` @yieldparam [Object] value The option value as parsed using `on` argument @yieldparam [OptionParser] options (nil) optional OptionParser
@yieldreturn [Object] a possibly modified input value
Public Instance Methods
Source
# File lib/rdf/cli.rb, line 150 def call(arg, options = {}) if @callback case @callback.arity when 0 then @callback.call when 1 then @callback.call(arg) when 2 then @callback.call(arg, options) else arg end else arg end end
Source
# File lib/rdf/cli.rb, line 164 def to_hash { symbol: symbol, datatype: (datatype.is_a?(Class) ? datatype.name : datatype), default: default, control: control, description: description, use: use } end
Return version of commands appropriate for use in JSON