class I18n::Tasks::Scanners::Results::KeyOccurrences
A scanned key and all its occurrences.
@note This is a value type. Equality and hash code are determined from the attributes.
Attributes
key[R]
@return [String] the key.
occurrences[R]
@return [Array<Occurrence>] the key's occurrences.
Public Class Methods
merge_keys(keys_occurrences)
click to toggle source
Merge {KeyOccurrences} in an {Enumerable<KeyOccurrences>} so that in the resulting {Array<KeyOccurrences>}:
-
Each key occurs only once.
-
{Occurrence}s from multiple instances of the key are merged.
-
The order of keys is preserved, occurrences are ordered by {Occurrence#path}.
@param keys_occurrences [Enumerable<KeyOccurrences>] @return [Array<KeyOccurrences>] a new array.
# File lib/i18n/tasks/scanners/results/key_occurrences.rb, line 43 def self.merge_keys(keys_occurrences) keys_occurrences.each_with_object({}) do |key_occurrences, results_by_key| (results_by_key[key_occurrences.key] ||= []) << key_occurrences.occurrences end.map do |key, all_occurrences| occurrences = all_occurrences.flatten(1) occurrences.sort_by!(&:path) occurrences.uniq! new(key: key, occurrences: occurrences) end end
new(key:, occurrences:)
click to toggle source
# File lib/i18n/tasks/scanners/results/key_occurrences.rb, line 16 def initialize(key:, occurrences:) @key = key @occurrences = occurrences end
Public Instance Methods
==(other)
click to toggle source
# File lib/i18n/tasks/scanners/results/key_occurrences.rb, line 21 def ==(other) other.key == @key && other.occurrences == @occurrences end
eql?(other)
click to toggle source
# File lib/i18n/tasks/scanners/results/key_occurrences.rb, line 25 def eql?(other) self == other end
hash()
click to toggle source
# File lib/i18n/tasks/scanners/results/key_occurrences.rb, line 29 def hash [@key, @occurrences].hash end
inspect()
click to toggle source
# File lib/i18n/tasks/scanners/results/key_occurrences.rb, line 33 def inspect "KeyOccurrences(#{key.inspect}, [#{occurrences.map(&:inspect).join(', ')}])" end