mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Addressing code review comments
This commit is contained in:
parent
e135ed817a
commit
479048980a
1 changed files with 20 additions and 31 deletions
|
@ -13,13 +13,10 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def format
|
def format
|
||||||
case
|
if array.empty?
|
||||||
when array.empty?
|
"[]"
|
||||||
empty_array
|
elsif methods_array?
|
||||||
when awesome_array?
|
|
||||||
methods_array
|
methods_array
|
||||||
when multiline_array?
|
|
||||||
multiline_array
|
|
||||||
else
|
else
|
||||||
simple_array
|
simple_array
|
||||||
end
|
end
|
||||||
|
@ -27,28 +24,26 @@ module AwesomePrint
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def awesome_array?
|
def methods_array?
|
||||||
array.instance_variable_defined?('@__awesome_methods__')
|
array.instance_variable_defined?('@__awesome_methods__')
|
||||||
end
|
end
|
||||||
|
|
||||||
def multiline_array?
|
|
||||||
options[:multiline]
|
|
||||||
end
|
|
||||||
|
|
||||||
def empty_array
|
|
||||||
"[]"
|
|
||||||
end
|
|
||||||
|
|
||||||
def simple_array
|
def simple_array
|
||||||
"[ " << array.map{ |item| inspector.awesome(item) }.join(", ") << " ]"
|
if options[:multiline]
|
||||||
|
multiline_array
|
||||||
|
else
|
||||||
|
"[ " << array.map{ |item| inspector.awesome(item) }.join(", ") << " ]"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def multiline_array
|
def multiline_array
|
||||||
data = generate_printable_array
|
data = unless should_be_limited?
|
||||||
data = limited(data, width(array)) if should_be_limited?
|
generate_printable_array
|
||||||
data = data.join(",\n")
|
else
|
||||||
|
limited(generate_printable_array, width(array))
|
||||||
|
end
|
||||||
|
|
||||||
"[\n#{data}\n#{outdent}]"
|
%Q([\n#{data.join(",\n")}\n#{outdent}])
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_printable_array
|
def generate_printable_array
|
||||||
|
@ -86,10 +81,9 @@ module AwesomePrint
|
||||||
def tuple_template(item)
|
def tuple_template(item)
|
||||||
name_width, args_width = name_and_args_width
|
name_width, args_width = name_and_args_width
|
||||||
|
|
||||||
str = ""
|
str = "#{colorize(item[0].rjust(name_width), :method)}"
|
||||||
str += "#{colorize(item[0].rjust(name_width), :method)}"
|
str << "#{colorize(item[1].ljust(args_width), :args)} "
|
||||||
str += "#{colorize(item[1].ljust(args_width), :args)} "
|
str << "#{colorize(item[2], :class)}"
|
||||||
str += "#{colorize(item[2], :class)}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def tuples
|
def tuples
|
||||||
|
@ -97,14 +91,9 @@ module AwesomePrint
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_and_args_width
|
def name_and_args_width
|
||||||
name_width, args_width = 0, 0
|
name_and_args = tuples.transpose
|
||||||
|
|
||||||
tuples.each do |item|
|
return name_and_args[0].map(&:size).max, name_and_args[1].map(&:size).max
|
||||||
name_width = [name_width, item[0].size].max
|
|
||||||
args_width = [args_width, item[1].size].max
|
|
||||||
end
|
|
||||||
|
|
||||||
return name_width, args_width
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def tuple_prefix(iteration, width)
|
def tuple_prefix(iteration, width)
|
||||||
|
|
Loading…
Add table
Reference in a new issue