Sha256: 4a55e85c2ef720f89c606060db1e6eb3a77adf36870c5b38274f8ceb6d7ad047

Contents?: true

Size: 1.54 KB

Versions: 20

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true
module YARD
  module I18n
    # Acts as a container for {Message} objects.
    #
    # @since 0.8.1
    class Messages
      include Enumerable

      # Creates a new container.
      def initialize
        @messages = {}
      end

      # Enumerates each {Message} in the container.
      #
      # @yieldparam [Message] message the next message object in
      #   the enumeration.
      # @return [void]
      def each(&block)
        @messages.each_value(&block)
      end

      # @param [String] id the message ID to perform a lookup on.
      # @return [Message, nil] a registered message for the given +id+,
      #   or nil if no message for the ID is found.
      def [](id)
        @messages[id]
      end

      # Registers a {Message}, the message ID of which is +id+. If
      # corresponding +Message+ is already registered, the previously
      # registered object is returned.
      #
      # @param [String] id the ID of the message to be registered.
      # @return [Message] the registered +Message+.
      def register(id)
        @messages[id] ||= Message.new(id)
      end

      # Checks if this messages list is equal to another messages list.
      #
      # @param [Messages] other the container to compare.
      # @return [Boolean] whether +self+ and +other+ is equivalence or not.
      def ==(other)
        other.is_a?(self.class) &&
          @messages == other.messages
      end

      protected

      # @return [Hash{String=>Message}] the set of message objects
      attr_reader :messages
    end
  end
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
kinetic_sdk-5.0.29 gems/yard-0.9.36/lib/yard/i18n/messages.rb
kinetic_sdk-5.0.28 gems/yard-0.9.36/lib/yard/i18n/messages.rb
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/messages.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/messages.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/messages.rb
yard-0.9.37 lib/yard/i18n/messages.rb
kinetic_sdk-5.0.27 gems/yard-0.9.36/lib/yard/i18n/messages.rb
kinetic_sdk-5.0.26 gems/yard-0.9.36/lib/yard/i18n/messages.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/messages.rb
yard-0.9.36 lib/yard/i18n/messages.rb
yard-0.9.35 lib/yard/i18n/messages.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/messages.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/yard-0.9.34/lib/yard/i18n/messages.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/i18n/messages.rb
yard-0.9.34 lib/yard/i18n/messages.rb
yard-0.9.33 lib/yard/i18n/messages.rb
yard-0.9.32 lib/yard/i18n/messages.rb
yard-0.9.31 lib/yard/i18n/messages.rb
yard-0.9.30 lib/yard/i18n/messages.rb
yard-0.9.29 lib/yard/i18n/messages.rb