lib/mercenary/option.rb in mercenary-0.3.6 vs lib/mercenary/option.rb in mercenary-0.4.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module Mercenary
class Option
attr_reader :config_key, :description, :short, :long, :return_type
# Public: Create a new Option
@@ -9,14 +11,14 @@
# info - an array containing first the switches, then an optional
# return type (e.g. Array), then a description of the option
#
# Returns nothing
def initialize(config_key, info)
- @config_key = config_key
+ @config_key = config_key
while arg = info.shift
begin
- @return_type = Object.const_get("#{arg}")
+ @return_type = Object.const_get(arg.to_s)
next
rescue NameError
end
if arg.start_with?("-")
if arg.start_with?("--")
@@ -32,11 +34,11 @@
# Public: Fetch the array containing the info OptionParser is interested in
#
# Returns the array which OptionParser#on wants
def for_option_parser
- [short, long, return_type, description].flatten.reject{ |o| o.to_s.empty? }
+ [short, long, return_type, description].flatten.reject { |o| o.to_s.empty? }
end
# Public: Build a string representation of this option including the
# switches and description
#
@@ -49,12 +51,12 @@
#
# Returns a formatted string representation of the switches
def formatted_switches
[
switches.first.rjust(10),
- switches.last.ljust(13)
- ].join(", ").gsub(/ , /, ' ').gsub(/, /, ' ')
+ switches.last.ljust(13),
+ ].join(", ").gsub(%r! , !, " ").gsub(%r!, !, " ")
end
# Public: Hash based on the hash value of instance variables
#
# Returns a Fixnum which is unique to this Option based on the instance variables
@@ -68,10 +70,11 @@
# instance variables
#
# Returns true if all the instance variables are equal, false otherwise
def eql?(other)
return false unless self.class.eql?(other.class)
+
instance_variables.map do |var|
instance_variable_get(var).eql?(other.instance_variable_get(var))
end.all?
end
@@ -80,8 +83,7 @@
# Returns an array of two strings. An empty string represents no switch in
# that position.
def switches
[short, long].map(&:to_s)
end
-
end
end