Class: Spellr::BaseReporter

Inherits:
Object
  • Object
show all
Includes:
StringFormat
Defined in:
lib/spellr/base_reporter.rb

Instance Method Summary collapse

Methods included from StringFormat

aqua, bold, green, key, lighten, normal, pluralize, red

Constructor Details

#initialize(output = nil) ⇒ BaseReporter

Returns a new instance of BaseReporter.



10
11
12
# File 'lib/spellr/base_reporter.rb', line 10

def initialize(output = nil)
  @output = output
end

Instance Method Details

#call(token) ⇒ Object



18
19
20
# File 'lib/spellr/base_reporter.rb', line 18

def call(token)
  puts "#{aqua token.location} #{token.line.highlight(token.char_range).strip}"
end

#countsObject



46
47
48
# File 'lib/spellr/base_reporter.rb', line 46

def counts
  output.counts
end

#exit_codeObject



38
39
40
# File 'lib/spellr/base_reporter.rb', line 38

def exit_code
  output.exit_code
end

#finishObject



14
15
16
# File 'lib/spellr/base_reporter.rb', line 14

def finish
  nil
end

#increment(counter) ⇒ Object



22
23
24
# File 'lib/spellr/base_reporter.rb', line 22

def increment(counter)
  output.increment(counter)
end

#outputObject



42
43
44
# File 'lib/spellr/base_reporter.rb', line 42

def output
  @output ||= Spellr.config.output
end


30
31
32
# File 'lib/spellr/base_reporter.rb', line 30

def print(str)
  output.print(str)
end


50
51
52
# File 'lib/spellr/base_reporter.rb', line 50

def print_count(stat, noun, verb = stat, hide_zero: false)
  print_value(counts[stat], noun, verb, hide_zero: hide_zero)
end


54
55
56
# File 'lib/spellr/base_reporter.rb', line 54

def print_value(value, noun, verb, hide_zero: false)
  puts "#{pluralize noun, value} #{verb}" if !hide_zero || value.positive?
end

#puts(str) ⇒ Object



26
27
28
# File 'lib/spellr/base_reporter.rb', line 26

def puts(str)
  output.puts(str)
end

#warn(str) ⇒ Object



34
35
36
# File 'lib/spellr/base_reporter.rb', line 34

def warn(str)
  output.warn(str)
end