Sha256: 3e95ab758ceaa2884fb189eef7bc9910027eb415737149830e14a28add62f746

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

module I18nAdminUtils
  class SearchResult
    attr_accessor :results

    def initialize(array= [])
      @results = array
    end


    def [](i)
      @results[i]
    end

    def []=(i, translation)
      existing = find_by_key(translation.key)
      if existing.nil?
        if i == -1
          @results << translation
        else
          @results[i] = translation
        end
      else
        existing.locations += translation.locations
      end
    end

    def <<(translation)
      self[-1] = translation
    end

    def +(other)
      SearchResult.new(@results + other.results)
    end

    def find_by_key(key)
      @results.select { |h| not h.nil? and h.key == key }.first
    end

    def include_key?(key)
      @results.any? { |h| not h.nil? and h.key == key }
    end


    def to_s
      @results.to_s
    end

    delegate :first, :last, :size, :each, :delete, :to => :results

    alias :count :size
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i18n_admin_utils-1.1.0 lib/i18n_admin_utils/search_result.rb