Class: Jt
- Inherits:
-
Object
- Object
- Jt
- Defined in:
- lib/jt.rb,
lib/jt/version.rb
Constant Summary collapse
- SPACE_SIZE =
8- T_LINE =
'├────'- I_LINE =
'│'- L_LINE =
'└────'- VALUES =
Regexp.union( [ "true", "false", "null", /[+-]?\d+\.?\d*/, /".*"/ ] )
- VERSION =
"0.3.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text) ⇒ Jt
constructor
A new instance of Jt.
- #to_s ⇒ Object
Constructor Details
#initialize(text) ⇒ Jt
Returns a new instance of Jt.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jt.rb', line 24 def initialize(text) object = JSON.parse(text) @queue = [] if object.instance_of?(Hash) @queue << "root\n".colorize(:red) parse(object) elsif text =~ VALUES @queue << "#{output_value(object)}\n" return else raise "Unexpected value #{object.inspect}" end end |
Class Method Details
.create(text) ⇒ Object
20 21 22 |
# File 'lib/jt.rb', line 20 def self.create(text) new(text) end |
Instance Method Details
#to_s ⇒ Object
39 40 41 |
# File 'lib/jt.rb', line 39 def to_s @queue.join end |