Class: Far::Option
- Inherits:
-
Object
- Object
- Far::Option
- Defined in:
- lib/far/option.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #boolean? ⇒ Boolean
- #equals ⇒ Object
- #far_option? ⇒ Boolean
- #flag? ⇒ Boolean
-
#initialize(key, value) ⇒ Option
constructor
A new instance of Option.
- #negator ⇒ Object
- #prefix ⇒ Object
- #switch? ⇒ Boolean
- #to_command_line ⇒ Object
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
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/far/option.rb', line 3 def key @key end |
#value ⇒ Object
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
34 35 36 |
# File 'lib/far/option.rb', line 34 def boolean? !!@value == @value end |
#equals ⇒ Object
30 31 32 |
# File 'lib/far/option.rb', line 30 def equals "=" unless boolean? end |
#far_option? ⇒ Boolean
14 15 16 |
# File 'lib/far/option.rb', line 14 def far_option? Options..include? @key.to_sym end |
#flag? ⇒ Boolean
18 19 20 |
# File 'lib/far/option.rb', line 18 def flag? @key.length > 1 end |
#negator ⇒ Object
26 27 28 |
# File 'lib/far/option.rb', line 26 def negator "no-" unless @value end |
#prefix ⇒ Object
38 39 40 41 |
# File 'lib/far/option.rb', line 38 def prefix return "--" if flag? return "-" if switch? end |
#switch? ⇒ Boolean
22 23 24 |
# File 'lib/far/option.rb', line 22 def switch? @key.length == 1 end |
#to_command_line ⇒ Object
10 11 12 |
# File 'lib/far/option.rb', line 10 def to_command_line "#{prefix}#{negator}#{@key.gsub(/\_/) { |k| "-" }}#{equals}#{@value unless boolean?}" end |