Class: Far::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/far/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ Option

Returns a new instance of Option.



5
6
7
8
# File 'lib/far/option.rb', line 5

def initialize(key, value)
  @key   = key.to_s
  @value = value
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/far/option.rb', line 3

def key
  @key
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/far/option.rb', line 3

def value
  @value
end

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/far/option.rb', line 34

def boolean?
  !!@value == @value
end

#equalsObject



30
31
32
# File 'lib/far/option.rb', line 30

def equals
  "=" unless boolean?
end

#far_option?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/far/option.rb', line 14

def far_option?
  Options.far_options.include? @key.to_sym
end

#flag?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/far/option.rb', line 18

def flag?
  @key.length > 1
end

#negatorObject



26
27
28
# File 'lib/far/option.rb', line 26

def negator
  "no-" unless @value
end

#prefixObject



38
39
40
41
# File 'lib/far/option.rb', line 38

def prefix
  return "--" if flag?
  return "-"  if switch?
end

#switch?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/far/option.rb', line 22

def switch?
  @key.length == 1
end

#to_command_lineObject



10
11
12
# File 'lib/far/option.rb', line 10

def to_command_line
  "#{prefix}#{negator}#{@key.gsub(/\_/) { |k| "-" }}#{equals}#{@value unless boolean?}"
end