summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2017-07-02 02:13:31 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2017-07-02 02:13:31 -0300
commit174a063138ab757fd090b2a1b283b786ca573899 (patch)
tree9ca5d8b2ecb861e588dc3c4cf966bfb67c0506ee
parent1c35f06613c0813110b5887b3ab3f2f67457391c (diff)
downloadhighline-174a063138ab757fd090b2a1b283b786ca573899.tar.gz
More manual fixes for rubocop warnings
-rw-r--r--lib/highline/simulate.rb13
-rw-r--r--lib/highline/statement.rb12
-rw-r--r--lib/highline/string.rb14
-rw-r--r--lib/highline/string_extensions.rb16
-rwxr-xr-xlib/highline/style.rb25
5 files changed, 53 insertions, 27 deletions
diff --git a/lib/highline/simulate.rb b/lib/highline/simulate.rb
index c0bb585..f92eaa3 100644
--- a/lib/highline/simulate.rb
+++ b/lib/highline/simulate.rb
@@ -25,14 +25,15 @@ class HighLine
@strings.shift
end
- # Simulate StringIO#getbyte by shifting a single character off of the next line of the script
+ # Simulate StringIO#getbyte by shifting a single character off of
+ # the next line of the script
def getbyte
line = gets
- unless line.empty?
- char = line.slice! 0
- @strings.unshift line
- char
- end
+ return if line.empty?
+
+ char = line.slice! 0
+ @strings.unshift line
+ char
end
# The simulator handles its own EOF
diff --git a/lib/highline/statement.rb b/lib/highline/statement.rb
index b5938a9..85035e4 100644
--- a/lib/highline/statement.rb
+++ b/lib/highline/statement.rb
@@ -45,6 +45,10 @@ class HighLine
statement
end
+ def self.const_missing(constant)
+ HighLine.const_get(constant)
+ end
+
private
def stringfy(template_string)
@@ -59,7 +63,9 @@ class HighLine
statement = HighLine::Wrapper.wrap(statement, highline.wrap_at)
statement = HighLine::Paginator.new(highline).page_print(statement)
- statement = statement.gsub(/\n(?!$)/, "\n#{highline.indentation}") if highline.multi_indent
+ statement = statement.gsub(/\n(?!$)/, "\n#{highline.indentation}") if
+ highline.multi_indent
+
statement
end
@@ -74,9 +80,5 @@ class HighLine
def template
@template ||= ERB.new(template_string, nil, "%")
end
-
- def self.const_missing(constant)
- HighLine.const_get(constant)
- end
end
end
diff --git a/lib/highline/string.rb b/lib/highline/string.rb
index 7ceb244..8d2e0a6 100644
--- a/lib/highline/string.rb
+++ b/lib/highline/string.rb
@@ -4,10 +4,12 @@ require "highline/string_extensions"
class HighLine
#
- # HighLine::String is a subclass of String with convenience methods added for colorization.
+ # HighLine::String is a subclass of String with convenience methods added
+ # for colorization.
#
# Available convenience methods include:
- # * 'color' method e.g. highline_string.color(:bright_blue, :underline)
+ # * 'color' method e.g. highline_string.color(:bright_blue,
+ # :underline)
# * colors e.g. highline_string.magenta
# * RGB colors e.g. highline_string.rgb_ff6000
# or highline_string.rgb(255,96,0)
@@ -16,18 +18,18 @@ class HighLine
# or highline_string.on_rgb(255,96,0)
# * styles e.g. highline_string.underline
#
- # Additionally, convenience methods can be chained, for instance the following are equivalent:
+ # Additionally, convenience methods can be chained, for instance the
+ # following are equivalent:
# highline_string.bright_blue.blink.underline
# highline_string.color(:bright_blue, :blink, :underline)
# HighLine.color(highline_string, :bright_blue, :blink, :underline)
#
- # For those less squeamish about possible conflicts, the same convenience methods can be
- # added to the built-in String class, as follows:
+ # For those less squeamish about possible conflicts, the same convenience
+ # methods can be added to the built-in String class, as follows:
#
# require 'highline'
# Highline.colorize_strings
#
-
class String < ::String
include StringExtensions
end
diff --git a/lib/highline/string_extensions.rb b/lib/highline/string_extensions.rb
index 95c8bd5..5c50977 100644
--- a/lib/highline/string_extensions.rb
+++ b/lib/highline/string_extensions.rb
@@ -61,15 +61,25 @@ class HighLine
if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
color(method)
else
- raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{format('%#x', object_id)}>"
+ raise NoMethodError, "undefined method `#{method}' for" /
+ "#<#{self.class}:#{format('%#x', object_id)}>"
end
end
private
def setup_color_code(*colors)
- color_code = colors.map { |color| color.is_a?(Numeric) ? format('%02x', color) : color.to_s }.join
- raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
+ color_code = colors.map do |color|
+ if color.is_a?(Numeric)
+ format('%02x', color)
+ else
+ color.to_s
+ end
+ end.join
+
+ raise "Bad RGB color #{colors.inspect}" unless
+ color_code =~ /^[a-fA-F0-9]{6}/
+
color_code
end
end
diff --git a/lib/highline/style.rb b/lib/highline/style.rb
index 8d6cebc..1ac66c4 100755
--- a/lib/highline/style.rb
+++ b/lib/highline/style.rb
@@ -31,13 +31,14 @@ class HighLine
if arg.is_a?(Style)
Style.list[arg.name] || Style.index(arg)
elsif arg.is_a?(::String) && arg =~ /^\e\[/ # arg is a code
- if styles = Style.code_index[arg]
+ styles = Style.code_index[arg]
+ if styles
styles.first
else
Style.new(code: arg)
end
- elsif style = Style.list[arg]
- style
+ elsif Style.list[arg]
+ Style.list[arg]
elsif HighLine.color_scheme && HighLine.color_scheme[arg]
HighLine.color_scheme[arg]
elsif arg.is_a?(Hash)
@@ -77,7 +78,9 @@ class HighLine
unless style.list
@code_index ||= {}
@code_index[style.code] ||= []
- @code_index[style.code].reject! { |indexed_style| indexed_style.name == style.name }
+ @code_index[style.code].reject! do |indexed_style|
+ indexed_style.name == style.name
+ end
@code_index[style.code] << style
end
style
@@ -139,11 +142,14 @@ class HighLine
end
# Returns the rgb number to be used as escape code on ANSI terminals.
- # @param parts [Array<Numeric>] three numerical codes for red, green and blue
+ # @param parts [Array<Numeric>] three numerical codes for red, green
+ # and blue
# @return [Numeric] to be used as escape code on ANSI terminals
def self.rgb_number(*parts)
parts = parts.flatten
- 16 + parts.reduce(0) { |kode, part| kode * 6 + (part / 256.0 * 6.0).floor }
+ 16 + parts.reduce(0) do |kode, part|
+ kode * 6 + (part / 256.0 * 6.0).floor
+ end
end
# From an ANSI number (color escape code), craft an 'rgb_hex' code of it
@@ -151,7 +157,12 @@ class HighLine
# @return [String] all color codes joined as {.rgb_hex}
def self.ansi_rgb_to_hex(ansi_number)
raise "Invalid ANSI rgb code #{ansi_number}" unless (16..231).cover?(ansi_number)
- parts = (ansi_number - 16).to_s(6).rjust(3, '0').scan(/./).map { |d| (d.to_i * 255.0 / 6.0).ceil }
+ parts = (ansi_number - 16).
+ to_s(6).
+ rjust(3, '0').
+ scan(/./).
+ map { |d| (d.to_i * 255.0 / 6.0).ceil }
+
rgb_hex(*parts)
end