Class: MGit::ARGV::OptList
- Inherits:
-
Object
- Object
- MGit::ARGV::OptList
- Defined in:
- lib/m-git/argv/opt_list.rb
Overview
参数对象列表
Instance Attribute Summary collapse
-
#opts ⇒ Object
- Array<ARGV::Opt>
-
参数对象数组.
Instance Method Summary collapse
-
#did_register_opt?(key) ⇒ Boolean
判断参数是否注册过.
-
#did_set_opt?(key) ⇒ Boolean
判断参数是否设置过值.
-
#initialize(opts) ⇒ OptList
constructor
attr_reader :valid_opts.
-
#opt(key) ⇒ ARGV::Opt
(also: #opt_with)
获取某个参数对象.
-
#opts_ordered_by_priority ⇒ Array<ARGV::Opt>
将参数根据优先级排序(逆序)后返回.
-
#registered_opt(key) ⇒ ARGV::Opt
返回某个注册过的参数对象.
- #valid_opts ⇒ Object
Constructor Details
#initialize(opts) ⇒ OptList
attr_reader :valid_opts
13 14 15 |
# File 'lib/m-git/argv/opt_list.rb', line 13 def initialize(opts) @opts = opts end |
Instance Attribute Details
#opts ⇒ Object
- Array<ARGV::Opt>
-
参数对象数组
9 10 11 |
# File 'lib/m-git/argv/opt_list.rb', line 9 def opts @opts end |
Instance Method Details
#did_register_opt?(key) ⇒ Boolean
判断参数是否注册过
56 57 58 |
# File 'lib/m-git/argv/opt_list.rb', line 56 def did_register_opt?(key) !registered_opt(key).nil? end |
#did_set_opt?(key) ⇒ Boolean
判断参数是否设置过值
36 37 38 |
# File 'lib/m-git/argv/opt_list.rb', line 36 def did_set_opt?(key) !opt(key).nil? end |
#opt(key) ⇒ ARGV::Opt Also known as: opt_with
获取某个参数对象
27 28 29 |
# File 'lib/m-git/argv/opt_list.rb', line 27 def opt(key) valid_opts.find { |e| (e.key == key || e.short_key == key) } end |
#opts_ordered_by_priority ⇒ Array<ARGV::Opt>
将参数根据优先级排序(逆序)后返回
64 65 66 67 |
# File 'lib/m-git/argv/opt_list.rb', line 64 def opts_ordered_by_priority # 按照优先级进行降序排序 opts.sort_by { |e| e.priority }.reverse end |
#registered_opt(key) ⇒ ARGV::Opt
返回某个注册过的参数对象
48 49 50 |
# File 'lib/m-git/argv/opt_list.rb', line 48 def registered_opt(key) @opts.find { |e| (e.key == key || e.short_key == key) } end |
#valid_opts ⇒ Object
17 18 19 |
# File 'lib/m-git/argv/opt_list.rb', line 17 def valid_opts @opts.select { |e| !e.empty? } end |