Class: RDF::CLI::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/cli.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol: nil, on: nil, description: nil, datatype: String, multiple: false) {|value| ... } ⇒ Option

Create a new option with optional callback.

Parameters:

  • symbol (Symbol) (defaults to: nil)
  • on (Array<String>) (defaults to: nil)
  • description (String) (defaults to: nil)
  • datatype (Class, Array<String>) (defaults to: String)

    of value

  • multiple (Boolean) (defaults to: false)

    can have multiple comma-separated values

Yields:

  • value which may be used within ‘OptionParser#on`

Yield Parameters:

  • value (Object)

    The option value as parsed using ‘on` argument

Yield Returns:

  • (Object)

    a possibly modified input value

Raises:

  • (ArgumentError)


109
110
111
112
113
# File 'lib/rdf/cli.rb', line 109

def initialize(symbol: nil, on: nil, description: nil, datatype: String, multiple: false, &block)
  raise ArgumentError, "symbol is a required argument" unless symbol
  raise ArgumentError, "on is a required argument" unless on
  @symbol, @on, @description, @datatype, @multiple, @callback = symbol.to_sym, Array(on), description, datatype, multiple, block
end

Instance Attribute Details

#datatypeClass, Array<String> (readonly)

Argument datatype, which may be enumerated string values

Returns:

  • (Class, Array<String>)


92
93
94
# File 'lib/rdf/cli.rb', line 92

def datatype
  @datatype
end

#descriptionString (readonly)

Description of this option (optional)

Returns:

  • (String)


88
89
90
# File 'lib/rdf/cli.rb', line 88

def description
  @description
end

#multipleBoolean (readonly)

Allows multiple comma-spearated values.

Returns:

  • (Boolean)


96
97
98
# File 'lib/rdf/cli.rb', line 96

def multiple
  @multiple
end

#onArray<String> (readonly)

Arguments passed to OptionParser#on

Returns:

  • (Array<String>)


84
85
86
# File 'lib/rdf/cli.rb', line 84

def on
  @on
end

#symbolSymbol (readonly)

Symbol used for this option when calling ‘Reader.new`

Returns:

  • (Symbol)


80
81
82
# File 'lib/rdf/cli.rb', line 80

def symbol
  @symbol
end

Instance Method Details

#call(arg) ⇒ Object



115
116
117
# File 'lib/rdf/cli.rb', line 115

def call(arg)
  @callback ? @callback.call(arg) : arg
end