Class: OptConfig::Option
- Inherits:
-
Object
- Object
- OptConfig::Option
- Defined in:
- lib/optconfig.rb
Overview
オプション定義
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#completion ⇒ Object
readonly
Returns the value of attribute completion.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#in_config ⇒ Object
readonly
Returns the value of attribute in_config.
-
#multiple ⇒ Object
readonly
Returns the value of attribute multiple.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ovalue ⇒ Object
Returns the value of attribute ovalue.
-
#pre_proc ⇒ Object
readonly
Returns the value of attribute pre_proc.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
-
#underscore_is_hyphen ⇒ Object
readonly
Returns the value of attribute underscore_is_hyphen.
-
#usage_name ⇒ Object
readonly
Returns the value of attribute usage_name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Option
constructor
初期化 args:: オプション名(String) のリスト、オプションの属性(Hash).
- #may_not_take_argument? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Option
初期化
- args
-
オプション名(String) のリスト、オプションの属性(Hash)
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/optconfig.rb', line 483 def initialize(*args) name = args.dup if name.last.is_a? Hash attr = name.pop else attr = {} end raise "no option name: #{args.inspect}" if name.empty? argument = nil @usage_name = name @name = name.to_a.map do |n| unless n =~ /\A([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9_-]+)(\[?=.*)?\z/ raise "invalid option name: #{n.inspect}" end n = $1 argument = $2.nil? ? nil : $2 =~ /\A\[/ ? :optional : true n end @argument = attr.key?(:argument) ? attr[:argument] : argument @format = attr.key?(:format) ? attr[:format] : @argument ? true : nil @default = attr[:default] @description = attr[:description] @multiple = attr.key?(:multiple) ? attr[:multiple] : :last @completion = attr.key?(:completion) ? attr[:completion] : true @underscore_is_hyphen = attr[:underscore_is_hyphen] @in_config = attr.key?(:in_config) ? attr[:in_config] : true @proc = attr[:proc] @pre_proc = attr[:pre_proc] @value = @default @ovalue = @default end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
514 515 516 |
# File 'lib/optconfig.rb', line 514 def argument @argument end |
#completion ⇒ Object (readonly)
Returns the value of attribute completion.
515 516 517 |
# File 'lib/optconfig.rb', line 515 def completion @completion end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
514 515 516 |
# File 'lib/optconfig.rb', line 514 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
514 515 516 |
# File 'lib/optconfig.rb', line 514 def description @description end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
514 515 516 |
# File 'lib/optconfig.rb', line 514 def format @format end |
#in_config ⇒ Object (readonly)
Returns the value of attribute in_config.
515 516 517 |
# File 'lib/optconfig.rb', line 515 def in_config @in_config end |
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
514 515 516 |
# File 'lib/optconfig.rb', line 514 def multiple @multiple end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
514 515 516 |
# File 'lib/optconfig.rb', line 514 def name @name end |
#ovalue ⇒ Object
Returns the value of attribute ovalue.
517 518 519 |
# File 'lib/optconfig.rb', line 517 def ovalue @ovalue end |
#pre_proc ⇒ Object (readonly)
Returns the value of attribute pre_proc.
515 516 517 |
# File 'lib/optconfig.rb', line 515 def pre_proc @pre_proc end |
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
515 516 517 |
# File 'lib/optconfig.rb', line 515 def proc @proc end |
#underscore_is_hyphen ⇒ Object (readonly)
Returns the value of attribute underscore_is_hyphen.
515 516 517 |
# File 'lib/optconfig.rb', line 515 def underscore_is_hyphen @underscore_is_hyphen end |
#usage_name ⇒ Object (readonly)
Returns the value of attribute usage_name.
516 517 518 |
# File 'lib/optconfig.rb', line 516 def usage_name @usage_name end |
#value ⇒ Object
Returns the value of attribute value.
517 518 519 |
# File 'lib/optconfig.rb', line 517 def value @value end |
Instance Method Details
#may_not_take_argument? ⇒ Boolean
519 520 521 |
# File 'lib/optconfig.rb', line 519 def may_not_take_argument? argument == false or argument == :optional or (argument.nil? and !format) end |