Module: Trith::Shell::Inspect
- Defined in:
- lib/trith/shell/inspect.rb
Defined Under Namespace
Modules: Color
Class Method Summary (collapse)
- + (String) colorize(text, color)
- + (String) inspect(value, options = {})
- + (String) inspect_array(array, options = {})
- + (String) inspect_machine(machine, options = {})
- + (String) inspect_reference(uri, options = {})
- + (String) inspect_string(string, options = {})
Class Method Details
+ (String) colorize(text, color)
36 37 38 |
# File 'lib/trith/shell/inspect.rb', line 36 def self.colorize(text, color) !color ? text.to_s : [(Color.const_get(color.to_s.upcase) rescue nil), text.to_s, Color::NOTHING].join('') end |
+ (String) inspect(value, options = {})
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/trith/shell/inspect.rb', line 44 def self.inspect(value, = {}) case value when NilClass then colorize(:nil, [:color] ? :green : nil) when FalseClass then colorize(false, [:color] ? :green : nil) when TrueClass then colorize(true, [:color] ? :green : nil) when Symbol then colorize(value.to_s, [:color] ? :yellow : nil) when Numeric then colorize(value.inspect, [:color] ? :cyan : nil) when String then inspect_string(value, ) when Array then inspect_array(value, ) when RDF::URI then inspect_reference(value, ) when Machine then inspect_machine(value, ) else value.inspect end end |
+ (String) inspect_array(array, options = {})
74 75 76 77 78 |
# File 'lib/trith/shell/inspect.rb', line 74 def self.inspect_array(array, = {}) colorize('[', [:color] ? :green : nil) << array.to_ary.map { |element| inspect(element, ) }.join(' ') << colorize(']', [:color] ? :green : nil) end |
+ (String) inspect_machine(machine, options = {})
63 64 65 66 67 68 |
# File 'lib/trith/shell/inspect.rb', line 63 def self.inspect_machine(machine, = {}) ([:prefix].to_s || '') + ([:align] ? ' ' * [20 - inspect(machine.stack, :color => false).size, 0].max : '') + inspect(machine.stack, ) + ' : ' + inspect(machine.queue, ) end |
+ (String) inspect_reference(uri, options = {})
94 95 96 97 98 |
# File 'lib/trith/shell/inspect.rb', line 94 def self.inspect_reference(uri, = {}) colorize('<', [:color] ? :red : nil) << colorize(uri.to_uri.to_s, [:color] ? :cyan : nil) << colorize('>', [:color] ? :red : nil) end |
+ (String) inspect_string(string, options = {})
84 85 86 87 88 |
# File 'lib/trith/shell/inspect.rb', line 84 def self.inspect_string(string, = {}) colorize('"', [:color] ? :red : nil) << colorize(string.to_str.inspect[1...-1], [:color] ? :cyan : nil) << colorize('"', [:color] ? :red : nil) end |