1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Remove code duplication in array and tuple_prefix

https://github.com/awesome-print/awesome_print/pull/246#issuecomment-238190911
This commit is contained in:
Gerard Caulfield 2016-11-17 17:09:10 +11:00
parent fff7e50597
commit 1f07a679b8
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3

View file

@ -54,11 +54,7 @@ module AwesomePrint
end end
def array_prefix(iteration, width) def array_prefix(iteration, width)
if options[:index] generic_prefix(iteration, width)
indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array)
else
indent
end
end end
def methods_array def methods_array
@ -99,11 +95,7 @@ module AwesomePrint
end end
def tuple_prefix(iteration, width) def tuple_prefix(iteration, width)
if options[:index] generic_prefix(iteration, width, ' ')
indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array)
else
indent + ' '
end
end end
def generate_tuple(name) def generate_tuple(name)
@ -131,6 +123,14 @@ module AwesomePrint
end end
end end
def generic_prefix(iteration, width, padding='')
if options[:index]
indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array)
else
indent + padding
end
end
def width(items) def width(items)
(items.size - 1).to_s.size (items.size - 1).to_s.size
end end