class RDF::CLI::Option

Option description for use within Readers/Writers. See {RDF::Reader.options} and {RDF::Writer.options} for example usage.

Attributes

control[R]

Associated HTML form control @return [:text, :textarea, :radio, :checkbox, :select, :url, :url2, :none]

datatype[R]

Potential values (for select or radio) or Ruby datatype @return [Class, Array<String>]

default[R]

Default value for this option @return [Object]

description[R]

Description of this option (optional) @return [String]

on[R]

Arguments passed to OptionParser#on @return [Array<String>]

symbol[R]

Symbol used for this option when calling ‘Reader.new` @return [Symbol]

use[RW]

Use of this option @return [:optional, :disabled, :removed, :required]

Public Class Methods

new(symbol: nil, on: nil, datatype: nil, control: nil, description: nil, use: :optional, default: nil, **options, &block) click to toggle source

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

# 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

Public Instance Methods

call(arg, options = {}) click to toggle 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
to_hash() click to toggle source

Return version of commands appropriate for use in JSON

# 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