diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-06-30 23:53:15 -0300 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-06-30 23:53:15 -0300 |
commit | 97888f5f91f9675ef2f7809fe1cb423abf6099c8 (patch) | |
tree | d26f2898b93308ba8a3e12b5fd3b363a46a0ef59 /lib/highline/color_scheme.rb | |
parent | 7a63996d6eaccbe403c724f40a771e4a48c7ea34 (diff) | |
download | highline-97888f5f91f9675ef2f7809fe1cb423abf6099c8.tar.gz |
Rubocop automatic corrections
Diffstat (limited to 'lib/highline/color_scheme.rb')
-rw-r--r-- | lib/highline/color_scheme.rb | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/lib/highline/color_scheme.rb b/lib/highline/color_scheme.rb index 11cd687..a776fbf 100644 --- a/lib/highline/color_scheme.rb +++ b/lib/highline/color_scheme.rb @@ -8,7 +8,6 @@ # # This is Free Software. See LICENSE and COPYING for details - class HighLine # # ColorScheme objects encapsulate a named set of colors to be used in the @@ -49,15 +48,15 @@ class HighLine # constants. # # @param h [Hash] - def initialize( h = nil ) - @scheme = Hash.new + def initialize(h = nil) + @scheme = {} load_from_hash(h) if h yield self if block_given? end # Load multiple colors from key/value pairs. # @param h [Hash] - def load_from_hash( h ) + def load_from_hash(h) h.each_pair do |color_tag, constants| self[color_tag] = constants end @@ -66,20 +65,20 @@ class HighLine # Does this color scheme include the given tag name? # @param color_tag [#to_sym] # @return [Boolean] - def include?( color_tag ) + def include?(color_tag) @scheme.keys.include?(to_symbol(color_tag)) end # Allow the scheme to be accessed like a Hash. # @param color_tag [#to_sym] # @return [Style] - def []( color_tag ) + def [](color_tag) @scheme[to_symbol(color_tag)] end # Retrieve the original form of the scheme # @param color_tag [#to_sym] - def definition( color_tag ) + def definition(color_tag) style = @scheme[to_symbol(color_tag)] style && style.list end @@ -93,29 +92,28 @@ class HighLine # Allow the scheme to be set like a Hash. # @param color_tag [#to_sym] # @param constants [Array<Symbol>] Array of Style symbols - def []=( color_tag, constants ) - @scheme[to_symbol(color_tag)] = HighLine::Style.new(:name=>color_tag.to_s.downcase.to_sym, - :list=>constants, :no_index=>true) + def []=(color_tag, constants) + @scheme[to_symbol(color_tag)] = HighLine::Style.new(name: color_tag.to_s.downcase.to_sym, + list: constants, no_index: true) end # Retrieve the color scheme hash (in original definition format) # @return [Hash] scheme as Hash. It may be reused in a new ColorScheme. def to_hash - @scheme.inject({}) { |hsh, pair| key, value = pair; hsh[key] = value.list; hsh } + @scheme.each_with_object({}) { |pair, hsh| key, value = pair; hsh[key] = value.list; } end - private # Return a normalized representation of a color name. - def to_symbol( t ) + def to_symbol(t) t.to_s.downcase end # Return a normalized representation of a color setting. - def to_constant( v ) + def to_constant(v) v = v.to_s if v.is_a?(Symbol) - if v.is_a?(::String) then + if v.is_a?(::String) HighLine.const_get(v.upcase) else v @@ -130,16 +128,16 @@ class HighLine # <tt>:error</tt>, <tt>:warning</tt>, <tt>:notice</tt>, <tt>:info</tt>, # <tt>:debug</tt>, <tt>:row_even</tt>, and <tt>:row_odd</tt> colors. # - def initialize( h = nil ) + def initialize(_h = nil) scheme = { - :critical => [ :yellow, :on_red ], - :error => [ :bold, :red ], - :warning => [ :bold, :yellow ], - :notice => [ :bold, :magenta ], - :info => [ :bold, :cyan ], - :debug => [ :bold, :green ], - :row_even => [ :cyan ], - :row_odd => [ :magenta ] + critical: %i[yellow on_red], + error: %i[bold red], + warning: %i[bold yellow], + notice: %i[bold magenta], + info: %i[bold cyan], + debug: %i[bold green], + row_even: [:cyan], + row_odd: [:magenta] } super(scheme) end |