Class: Baf::Option
- Inherits:
-
Object
- Object
- Baf::Option
- Defined in:
- lib/baf/option.rb
Direct Known Subclasses
Constant Summary collapse
- LONG_PREFIX =
'--'.freeze
- LONG_NORMALIZE_SEARCH =
?_.freeze
- LONG_NORMALIZE_REPLACE =
?-.freeze
- LONG_WITH_ARG_GLUE =
' '.freeze
- PARSER_MESSAGE =
:on
- PARSER_MESSAGE_TAIL =
:on_tail
Instance Attribute Summary collapse
-
#arg ⇒ Object
Returns the value of attribute arg.
-
#block ⇒ Object
Returns the value of attribute block.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#long ⇒ Object
Returns the value of attribute long.
-
#short ⇒ Object
Returns the value of attribute short.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
- #block? ⇒ Boolean
- #env_definition ⇒ Object
-
#initialize(*args, tail: false) ⇒ Option
constructor
A new instance of Option.
- #tail? ⇒ Boolean
- #to_parser_arguments(env) ⇒ Object
Constructor Details
#initialize(*args, tail: false) ⇒ Option
Returns a new instance of Option.
12 13 14 15 16 |
# File 'lib/baf/option.rb', line 12 def initialize *args, tail: false attrs = args.size > 1 ? build_attrs(*args) : args[0] attrs.each { |k, v| send :"#{k}=", v } self.tail = tail end |
Instance Attribute Details
#arg ⇒ Object
Returns the value of attribute arg.
10 11 12 |
# File 'lib/baf/option.rb', line 10 def arg @arg end |
#block ⇒ Object
Returns the value of attribute block.
10 11 12 |
# File 'lib/baf/option.rb', line 10 def block @block end |
#desc ⇒ Object
Returns the value of attribute desc.
10 11 12 |
# File 'lib/baf/option.rb', line 10 def desc @desc end |
#long ⇒ Object
Returns the value of attribute long.
10 11 12 |
# File 'lib/baf/option.rb', line 10 def long @long end |
#short ⇒ Object
Returns the value of attribute short.
10 11 12 |
# File 'lib/baf/option.rb', line 10 def short @short end |
#tail ⇒ Object
Returns the value of attribute tail.
10 11 12 |
# File 'lib/baf/option.rb', line 10 def tail @tail end |
Instance Method Details
#block? ⇒ Boolean
22 23 24 |
# File 'lib/baf/option.rb', line 22 def block? !!block end |
#env_definition ⇒ Object
18 19 20 |
# File 'lib/baf/option.rb', line 18 def env_definition :accessor end |
#tail? ⇒ Boolean
26 27 28 |
# File 'lib/baf/option.rb', line 26 def tail? !!tail end |
#to_parser_arguments(env) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/baf/option.rb', line 30 def to_parser_arguments env = tail? ? PARSER_MESSAGE_TAIL : PARSER_MESSAGE mblock = if block? -> *args { block[*args, env] } else parser_argument_block env end [, "-#{short}", parser_argument_long, parser_argument_desc, mblock] end |