Class: RDF::CLI::Option
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/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.
143 144 145 146 147 148 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 143 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
123 124 125 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 123 def control @control end |
#datatype ⇒ Class, Array<String> (readonly)
Potential values (for select or radio) or Ruby datatype
119 120 121 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 119 def datatype @datatype end |
#default ⇒ Object (readonly)
Default value for this option
115 116 117 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 115 def default @default end |
#description ⇒ String (readonly)
Description of this option (optional)
111 112 113 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 111 def description @description end |
#on ⇒ Array<String> (readonly)
Arguments passed to OptionParser#on
107 108 109 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 107 def on @on end |
#symbol ⇒ Symbol (readonly)
Symbol used for this option when calling Reader.new
103 104 105 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 103 def symbol @symbol end |
#use ⇒ :optional, ...
Use of this option
127 128 129 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 127 def use @use end |
Instance Method Details
#call(arg, options = {}) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/cli.rb', line 150 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
164 165 166 167 168 169 170 171 172 173 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/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 |