Class: Strop::Opt
- Inherits:
-
Data
- Object
- Data
- Strop::Opt
- Defined in:
- lib/strop.rb,
lib/strop.rb
Overview
Parsed option with declaration, invocation name, value, and negation state. Used internally. Seen as member of Result. Opt[decl: optdecl, name: “verbose”, value: “2”] #=> Opt(decl: …, name: “verbose”, value: “2”, label: “verbose”, no: false)
Instance Attribute Summary collapse
-
#decl ⇒ Object
readonly
Returns the value of attribute decl.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#no ⇒ Object
(also: #no?)
readonly
Returns the value of attribute no.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #encode_with(coder) ⇒ Object
-
#initialize(decl:, name:, value: nil) ⇒ Opt
constructor
A new instance of Opt.
- #yes? ⇒ Boolean
Constructor Details
#initialize(decl:, name:, value: nil) ⇒ Opt
Returns a new instance of Opt.
79 80 81 82 83 |
# File 'lib/strop.rb', line 79 def initialize(decl:, name:, value: nil) label = decl.label # repeated here so can be pattern-matched against in case/in no = name =~ /\Ano-?/ && decl.names.member?($') # flag given in negated version: (given --no-foo and also accepts --foo) super(decl:, name:, value:, label:, no: !!no) end |
Instance Attribute Details
#decl ⇒ Object (readonly)
Returns the value of attribute decl
78 79 80 |
# File 'lib/strop.rb', line 78 def decl @decl end |
#label ⇒ Object (readonly)
Returns the value of attribute label
78 79 80 |
# File 'lib/strop.rb', line 78 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name
78 79 80 |
# File 'lib/strop.rb', line 78 def name @name end |
#no ⇒ Object (readonly) Also known as: no?
Returns the value of attribute no
78 79 80 |
# File 'lib/strop.rb', line 78 def no @no end |
#value ⇒ Object (readonly)
Returns the value of attribute value
78 79 80 |
# File 'lib/strop.rb', line 78 def value @value end |
Instance Method Details
#encode_with(coder) ⇒ Object
123 |
# File 'lib/strop.rb', line 123 def encode_with(coder) = (coder.map = { self.name => self.value }; coder.tag = nil) |
#yes? ⇒ Boolean
85 |
# File 'lib/strop.rb', line 85 def yes? = !no? |