null+****@clear*****
null+****@clear*****
Wed Jul 18 14:32:30 JST 2012
SUZUKI Miho 2012-07-18 14:32:30 +0900 (Wed, 18 Jul 2012) New Revision: f4837f3662a40f939685aab3a1594c22d3a99e10 https://github.com/logaling/logaling-command/commit/f4837f3662a40f939685aab3a1594c22d3a99e10 Merged c54901b: Merge pull request #72 from logaling/fix-format-output Log: Extract #max_str_size Modified files: lib/logaling/command/application.rb Modified: lib/logaling/command/application.rb (+7 -4) =================================================================== --- lib/logaling/command/application.rb 2012-07-18 13:09:50 +0900 (92f34f2) +++ lib/logaling/command/application.rb 2012-07-18 14:32:30 +0900 (f249d69) @@ -262,13 +262,12 @@ module Logaling::Command end terms =****@repos*****(source_term, glossary, options["dictionary"]) unless terms.empty? - max_str_size = terms.map{|term| term_print_size(term[:source_term])}.sort.last run_pager terms.each_with_index do |term, i| case options["output"] when "terminal" term_renderer = Logaling::Command::Renderers::TermDefaultRenderer.new(term, @repository, @config, options) - term_renderer.max_str_size = max_str_size + term_renderer.max_str_size = max_str_size(terms) term_renderer.render($stdout) when "csv" term_renderer = Logaling::Command::Renderers::TermCsvRenderer.new(term, @repository, @config, options) @@ -311,11 +310,11 @@ module Logaling::Command terms = glossary.terms unless terms.empty? run_pager - max_str_size = terms.map{|term| term_print_size(term[:source_term])}.sort.last + max_source_term_size = max_str_size(terms) terms.each do |term| target_string = "#{term[:target_term]}" target_string << "\t# #{term[:note]}" unless term[:note].empty? - printf(" %-#{max_str_size+10}s %s\n", term[:source_term], target_string) + printf(" %-#{max_source_term_size+10}s %s\n", term[:source_term], target_string) end else "glossary <#{@config.glossary}> not found" @@ -383,5 +382,9 @@ module Logaling::Command def term_print_size(string) string.each_char.map{|char| char.bytesize == 1 ? 1 : 2}.inject(0, &:+) end + + def max_str_size(terms) + terms.map{|term| term_print_size(term[:source_term])}.sort.last + end end end -------------- next part -------------- An HTML attachment was scrubbed... 다운로드