Class: RDF::CLI::Option
- Inherits:
-
Object
- Object
- RDF::CLI::Option
- 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
-
#control ⇒ :text, ...
readonly
Associated HTML form control.
-
#datatype ⇒ Class, Array<String>
readonly
Potential values (for select or radio) or Ruby datatype.
-
#default ⇒ Object
readonly
Default value for this option.
-
#description ⇒ String
readonly
Description of this option (optional).
-
#on ⇒ Array<String>
readonly
Arguments passed to OptionParser#on.
-
#symbol ⇒ Symbol
readonly
Symbol used for this option when calling
Reader.new
. -
#use ⇒ :optional, ...
Use of this option.
Instance Method Summary collapse
- #call(arg, options = {}) ⇒ Object
-
#initialize(symbol: nil, on: nil, datatype: nil, control: nil, description: nil, use: :optional, default: nil, **options) {|value, options| ... } ⇒ Option
constructor
Create a new option with optional callback.
-
#to_hash ⇒ Object
Return version of commands appropriate for use in JSON.
Constructor Details
#initialize(symbol: nil, on: nil, datatype: nil, control: nil, description: nil, use: :optional, default: nil, **options) {|value, options| ... } ⇒ Option
Create a new option with optional callback.
142 143 144 145 146 147 |
# File 'lib/rdf/cli.rb', line 142 def initialize(symbol: nil, on: nil, datatype: nil, control: nil, description: nil, use: :optional, default: nil, **, &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 |
Instance Attribute Details
#control ⇒ :text, ... (readonly)
Associated HTML form control
122 123 124 |
# File 'lib/rdf/cli.rb', line 122 def control @control end |
#datatype ⇒ Class, Array<String> (readonly)
Potential values (for select or radio) or Ruby datatype
118 119 120 |
# File 'lib/rdf/cli.rb', line 118 def datatype @datatype end |
#default ⇒ Object (readonly)
Default value for this option
114 115 116 |
# File 'lib/rdf/cli.rb', line 114 def default @default end |
#description ⇒ String (readonly)
Description of this option (optional)
110 111 112 |
# File 'lib/rdf/cli.rb', line 110 def description @description end |
#on ⇒ Array<String> (readonly)
Arguments passed to OptionParser#on
106 107 108 |
# File 'lib/rdf/cli.rb', line 106 def on @on end |
#symbol ⇒ Symbol (readonly)
Symbol used for this option when calling Reader.new
102 103 104 |
# File 'lib/rdf/cli.rb', line 102 def symbol @symbol end |
#use ⇒ :optional, ...
Use of this option
126 127 128 |
# File 'lib/rdf/cli.rb', line 126 def use @use end |
Instance Method Details
#call(arg, options = {}) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/rdf/cli.rb', line 149 def call(arg, = {}) if @callback case @callback.arity when 0 then @callback.call when 1 then @callback.call(arg) when 2 then @callback.call(arg, ) else arg end else arg end end |
#to_hash ⇒ Object
Return version of commands appropriate for use in JSON
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/rdf/cli.rb', line 163 def to_hash { symbol: symbol, datatype: (datatype.is_a?(Class) ? datatype.name : datatype), default: default, control: control, description: description, use: use } end |