Class: GitSwitch::Options
- Inherits:
-
Object
- Object
- GitSwitch::Options
- Defined in:
- lib/git_switch/options.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #flags ⇒ Object
- #global? ⇒ Boolean
-
#initialize(args) ⇒ Options
constructor
A new instance of Options.
- #list? ⇒ Boolean
- #valid_args? ⇒ Boolean
- #verbose? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Options
Returns a new instance of Options.
4 5 6 |
# File 'lib/git_switch/options.rb', line 4 def initialize(args) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/git_switch/options.rb', line 3 def args @args end |
Instance Method Details
#flags ⇒ Object
8 9 10 11 12 13 |
# File 'lib/git_switch/options.rb', line 8 def flags @flags ||= args.select do |arg| arg.match(/\A\-[glv]{1}\z/) || arg.match(/\A\-\-(global|list|verbose){1}\z/) end end |
#global? ⇒ Boolean
31 32 33 |
# File 'lib/git_switch/options.rb', line 31 def global? (flags.include? '-g') || (flags.include? '--global') end |
#list? ⇒ Boolean
27 28 29 |
# File 'lib/git_switch/options.rb', line 27 def list? (flags.include? '-l') || (flags.include? '--list') end |
#valid_args? ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/git_switch/options.rb', line 15 def valid_args? if list? && args.count > 1 puts "Invalid args" return false elsif no_flags?(args) || one_flag?(args) return true else puts "Invalid args" return false end end |
#verbose? ⇒ Boolean
35 36 37 |
# File 'lib/git_switch/options.rb', line 35 def verbose? (flags.include? '-v') || (flags.include? '--verbose') end |