Class: Saga::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/saga/verifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Verifier

Returns a new instance of Verifier.



5
6
7
# File 'lib/saga/verifier.rb', line 5

def initialize(document)
  @document = document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



3
4
5
# File 'lib/saga/verifier.rb', line 3

def document
  @document
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/saga/verifier.rb', line 13

def run
  return if structure.empty?

  reported = []
  structure.each do |title, details|
    if details[:duplicates].any?
      warning = "has multiple stories with the same id: " \
                "#{format_sentence(details[:duplicates])}"
      if title.strip != ""
        puts "* Section #{format_title(title)} #{warning}"
      else
        puts "* Document #{warning}"
      end
    end

    structure.each do |other_title, other_details|
      next if title == other_title

      reused = details[:ids] & other_details[:ids]
      if reused.any?
        pair = [title, other_title].sort
        unless reported.include?(pair)
          puts(
            "* Sections #{format_title(title)} and #{format_title(other_title)} " \
            "share story ids: #{format_sentence(reused)}"
          )
          reported << pair
        end
      end
    end
  end
end

#structureObject



9
10
11
# File 'lib/saga/verifier.rb', line 9

def structure
  @structure ||= build_structure
end