Class: GitSwitch::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/git_switch/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject (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

#flagsObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/git_switch/options.rb', line 31

def global?
  (flags.include? '-g') || (flags.include? '--global')
end

#list?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/git_switch/options.rb', line 27

def list?
  (flags.include? '-l') || (flags.include? '--list')
end

#valid_args?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


35
36
37
# File 'lib/git_switch/options.rb', line 35

def verbose?
  (flags.include? '-v') || (flags.include? '--verbose')
end