Class: Spellr::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/spellr/output.rb

Direct Known Subclasses

OutputStubbed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOutput

Returns a new instance of Output.



7
8
9
# File 'lib/spellr/output.rb', line 7

def initialize
  @exit_code = 0
end

Instance Attribute Details

#exit_codeObject

Returns the value of attribute exit_code.



5
6
7
# File 'lib/spellr/output.rb', line 5

def exit_code
  @exit_code
end

Instance Method Details

#<<(other) ⇒ Object

rubocop:disable Metrics/AbcSize



55
56
57
58
59
60
# File 'lib/spellr/output.rb', line 55

def <<(other) # rubocop:disable Metrics/AbcSize
  self.exit_code = other.exit_code
  stderr.puts other.stderr.string if other.stderr?
  stdout.puts other.stdout.string if other.stdout?
  counts.merge!(other.counts) { |_k, a, b| a + b }
end

#countsObject



31
32
33
# File 'lib/spellr/output.rb', line 31

def counts
  @counts ||= Hash.new(0)
end

#increment(counter) ⇒ Object



39
40
41
# File 'lib/spellr/output.rb', line 39

def increment(counter)
  counts[counter] += 1
end


51
52
53
# File 'lib/spellr/output.rb', line 51

def print(str)
  stdout.print(str)
end

#puts(str) ⇒ Object



43
44
45
# File 'lib/spellr/output.rb', line 43

def puts(str)
  stdout.puts(str)
end

#stderrObject



19
20
21
# File 'lib/spellr/output.rb', line 19

def stderr
  @stderr ||= $stderr
end

#stderr?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/spellr/output.rb', line 27

def stderr?
  defined?(@stderr)
end

#stdinObject



11
12
13
# File 'lib/spellr/output.rb', line 11

def stdin
  @stdin ||= $stdin
end

#stdoutObject



15
16
17
# File 'lib/spellr/output.rb', line 15

def stdout
  @stdout ||= $stdout
end

#stdout?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/spellr/output.rb', line 23

def stdout?
  defined?(@stdout)
end

#warn(str) ⇒ Object



47
48
49
# File 'lib/spellr/output.rb', line 47

def warn(str)
  stderr.puts(str)
end