Class: I18nKit::Comparer

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_kit/comparer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(documents) ⇒ Comparer

Returns a new instance of Comparer.



9
10
11
# File 'lib/i18n_kit/comparer.rb', line 9

def initialize(documents)
  @documents = documents
end

Instance Attribute Details

#documentsObject

Returns the value of attribute documents.



7
8
9
# File 'lib/i18n_kit/comparer.rb', line 7

def documents
  @documents
end

Instance Method Details

#[](document_name) ⇒ Object



13
14
15
16
# File 'lib/i18n_kit/comparer.rb', line 13

def [](document_name)
  @documents.each { |doc| return doc if doc.name == document_name }
  nil
end

#compareObject



18
19
20
21
22
# File 'lib/i18n_kit/comparer.rb', line 18

def compare
  documents_to_compare.each do |left, right|
    #puts "#{left.name} <=> #{right.name}"
  end
end

#documents_to_compare(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/i18n_kit/comparer.rb', line 24

def documents_to_compare(&block)
  docs = @documents.dup
  pairs = []
  while base = docs.shift do
    docs.each do |doc|
      #break if doc == docs.last
      if block_given?
        yield(base, doc)
      else
        pairs << [base, doc]
      end
    end
  end
  pairs
end