Class: Spellr::Output
- Inherits:
-
Object
- Object
- Spellr::Output
- Defined in:
- lib/spellr/output.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#exit_code ⇒ Object
Returns the value of attribute exit_code.
Instance Method Summary collapse
-
#<<(other) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #counts ⇒ Object
- #increment(counter) ⇒ Object
-
#initialize ⇒ Output
constructor
A new instance of Output.
- #print(str) ⇒ Object
- #puts(str) ⇒ Object
- #stderr ⇒ Object
- #stderr? ⇒ Boolean
- #stdin ⇒ Object
- #stdout ⇒ Object
- #stdout? ⇒ Boolean
- #warn(str) ⇒ Object
Constructor Details
#initialize ⇒ Output
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_code ⇒ Object
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 |
#counts ⇒ Object
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 |
#print(str) ⇒ Object
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 |
#stderr ⇒ Object
19 20 21 |
# File 'lib/spellr/output.rb', line 19 def stderr @stderr ||= $stderr end |
#stderr? ⇒ Boolean
27 28 29 |
# File 'lib/spellr/output.rb', line 27 def stderr? defined?(@stderr) end |
#stdin ⇒ Object
11 12 13 |
# File 'lib/spellr/output.rb', line 11 def stdin @stdin ||= $stdin end |
#stdout ⇒ Object
15 16 17 |
# File 'lib/spellr/output.rb', line 15 def stdout @stdout ||= $stdout end |
#stdout? ⇒ 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 |