Sha256: bf405af06401f41b5c50012b005d2cdabff0b054ce59e855b6ff077fc09ca9f9

Contents?: true

Size: 851 Bytes

Versions: 5

Compression:

Stored size: 851 Bytes

Contents

module SpellCheck
  class Report
    attr_reader :errata

    def initialize
      @errata = []
    end

    def typo_count
      @errata.size
    end

    def accept?
      status == 'Accept'
    end

    def reject?
      !accept?
    end

    def status
      typo_count.zero? ? 'Accept' : 'Reject'
    end

    def to_s
      [
          results,
          conclusions
      ].join("\n\n")
    end

    private

    def results
      header = %w(Location Text Pattern Expected)
      rows = errata.map do |typo|
        [
            typo.line_number,
            typo.place,
            ColorString.red(typo.pattern),
            ColorString.green(typo.expected)
        ]
      end

      Terminal::Table.new(headings: header, rows: rows)
    end

    def conclusions
      ColorString.red("result: #{typo_count} typo found.")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spellcheck-0.3.4 lib/spellcheck/report.rb
spellcheck-0.3.3 lib/spellcheck/report.rb
spellcheck-0.3.2 lib/spellcheck/report.rb
spellcheck-0.3.1 lib/spellcheck/report.rb
spellcheck-0.3.0 lib/spellcheck/report.rb