Class: Strop::Opt

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

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

#declObject (readonly)

Returns the value of attribute decl

Returns:

  • (Object)

    the current value of decl



78
79
80
# File 'lib/strop.rb', line 78

def decl
  @decl
end

#labelObject (readonly)

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



78
79
80
# File 'lib/strop.rb', line 78

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



78
79
80
# File 'lib/strop.rb', line 78

def name
  @name
end

#noObject (readonly) Also known as: no?

Returns the value of attribute no

Returns:

  • (Object)

    the current value of no



78
79
80
# File 'lib/strop.rb', line 78

def no
  @no
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Boolean)


85
# File 'lib/strop.rb', line 85

def yes? = !no?