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)


37
38
39
# File 'lib/git_switch/options.rb', line 37

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

#list?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/git_switch/options.rb', line 33

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

#usage?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/git_switch/options.rb', line 29

def usage?
  args.count == 0
end

#valid_args?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
# 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
  elsif usage?
    return true
  else
    puts "Invalid args"
    return false
  end
end

#verbose?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/git_switch/options.rb', line 41

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