From d6be58113cd53de5c64ddec97fe525dbc3bed421 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 8 Oct 2010 23:13:42 -0700 Subject: Improve output spacing code. --- omptagger | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/omptagger b/omptagger index 4397591..205717b 100755 --- a/omptagger +++ b/omptagger @@ -12,12 +12,16 @@ require 'getoptlong' require 'rubygems' require 'TagLib' -class Metadata - def output(tag, val) - spacing = 2 + @tags.keys.inject(0) do |length, object| - object.length > length ? object.length : length - end - tag.length +class Hash + def longest_key_length + self.keys.inject(0) do |length, key| + key.length > length ? key.length : length + end + end +end +class Metadata + def output(tag, val, spacing = 2) puts ' ' + tag + ' ' * spacing + val end end @@ -33,7 +37,7 @@ class VorbisComment < Metadata @tags.sort.each do |tag, val| val.each do |val| - output(tag, val) + output(tag, val, 2 + @tags.longest_key_length - tag.length) end end end -- cgit v1.2.3-70-g09d2