lib/yard/i18n/pot_generator.rb in yard-0.9.5 vs lib/yard/i18n/pot_generator.rb in yard-0.9.6

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require "stringio" module YARD module I18n # The +PotGenerator+ generates POT format string from @@ -117,24 +118,23 @@ # Comments of the +Message+ are used to generate the # translater-comment line that is started with "# ". # # @return [String] POT format string def generate - pot = header + pot = String.new(header) sorted_messages = @messages.sort_by do |message| - sorted_locations = message.locations.sort_by do |location| - location - end + sorted_locations = message.locations.sort sorted_locations.first || [] end sorted_messages.each do |message| generate_message(pot, message) end pot end private + def header <<-EOH # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. @@ -190,11 +190,11 @@ def register_message(id) @messages.register(id) end def extract_documents(object) - return if @extracted_objects.has_key?(object) + return if @extracted_objects.key?(object) @extracted_objects[object] = true case object when CodeObjects::NamespaceObject object.children.each do |child| @@ -239,17 +239,17 @@ extract_documents(tag) if Tags::OverloadTag === tag end def extract_tag_name(tag) return if tag.name.nil? - return if tag.name.is_a?(String) and tag.name.empty? + return if tag.name.is_a?(String) && tag.name.empty? key = "tag|#{tag.tag_name}|#{tag.name}" message = register_message(key) tag.object.files.each do |path, line| message.add_location(path, line) end - tag_label = "@#{tag.tag_name}" + tag_label = String.new("@#{tag.tag_name}") tag_label << " [#{tag.types.join(', ')}]" if tag.types message.add_comment(tag_label) end def extract_tag_text(tag) @@ -257,10 +257,10 @@ return if tag.text.empty? message = register_message(tag.text) tag.object.files.each do |path, line| message.add_location(path, line) end - tag_label = "@#{tag.tag_name}" + tag_label = String.new("@#{tag.tag_name}") tag_label << " [#{tag.types.join(', ')}]" if tag.types tag_label << " #{tag.name}" if tag.name message.add_comment(tag_label) end