Class: Specdiff::Hashprint
- Inherits:
-
Object
- Object
- Specdiff::Hashprint
- Defined in:
- lib/specdiff/hashprint.rb
Overview
Tries to print nested hash/array structures such that they are as convenient as possible for a diffing algorithm designed for text (like source code). Basically tries to reproduce consistent literal source code form for ruby hashes and arrays and objects (although it falls back to #inspect).
Constant Summary collapse
- INDENTATION_SPACES =
2
- SPACE =
" ".freeze
- COMMA =
",".freeze
- NEWLINE =
"\n".freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.call ⇒ Object
6 7 8 |
# File 'lib/specdiff/hashprint.rb', line 6 def self.call(...) new.call(...) end |
Instance Method Details
#call(thing) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/specdiff/hashprint.rb', line 15 def call(thing) @recursion_trail = [] @indentation_level = 0 @indentation_per_level = SPACE * INDENTATION_SPACES @indent = "" @next_value_is_hash_value = false @output = StringIO.new output(thing) @output.string end |