module Mustermann::Visualizer::PatternExtension
Mixin that will be added to {Mustermann::Pattern}.
Public Instance Methods
color_inspect(base_color = nil, **theme)
click to toggle source
@return [String] ANSI colorized version of {Mustermann::Pattern#inspect}
# File lib/mustermann/visualizer/pattern_extension.rb, line 53 def color_inspect(base_color = nil, **theme) base_color ||= Highlight::DEFAULT_THEME[:base01] template = is_a?(Composite) ? "*#<%p:(*%s*)>*" : "*#<%p:*%s*>*" Hansi.render(template, self.class, to_ansi(inspect: true, **theme), {"*" => base_color}) end
inspect()
click to toggle source
If invoked directly by IRB, same as {#color_inspect}, otherwise same as {Mustermann::Pattern#inspect}.
Calls superclass method
# File lib/mustermann/visualizer/pattern_extension.rb, line 48 def inspect caller_locations.first.base_label == '<module:IRB>' ? color_inspect : super end
pretty_print(q)
click to toggle source
If invoked directly by IRB, same as {#color_inspect}, otherwise same as Object#pretty_print.
Calls superclass method
# File lib/mustermann/visualizer/pattern_extension.rb, line 60 def pretty_print(q) if q.class.name.to_s[/[^:]+$/] == "ColorPrinter" q.text(color_inspect, inspect.length) else super end end
to_ansi(inspect: nil, **theme)
click to toggle source
@example
puts Mustermann.new("/:page").to_ansi
@return [String] ANSI colorized version of the pattern.
# File lib/mustermann/visualizer/pattern_extension.rb, line 13 def to_ansi(inspect: nil, **theme) Visualizer.highlight(self, **theme).to_ansi(inspect: inspect) end
to_html(inspect: nil, tag: :span, class_prefix: "mustermann_", css: :inline, **theme)
click to toggle source
@example
puts Mustermann.new("/:page").to_html
@return [String] HTML version of the pattern.
# File lib/mustermann/visualizer/pattern_extension.rb, line 21 def to_html(inspect: nil, tag: :span, class_prefix: "mustermann_", css: :inline, **theme) Visualizer.highlight(self, **theme).to_html(inspect: inspect, tag: tag, class_prefix: class_prefix, css: css) end
to_s()
click to toggle source
If invoked directly by puts: ANSI colorized version of the pattern. If invoked by anything else: String version of the pattern.
@example
require 'mustermann/visualizer' pattern = Mustermann.new('/:page') puts pattern # will have color puts pattern.to_s # will not have color
@return [String] non-colorized or colorized version of the pattern
Calls superclass method
# File lib/mustermann/visualizer/pattern_extension.rb, line 43 def to_s caller_locations.first.label == 'puts' ? to_ansi : super end
to_tree()
click to toggle source
@example
puts Mustermann.new("/:page").to_tree
@return [String] tree version of the pattern.
# File lib/mustermann/visualizer/pattern_extension.rb, line 29 def to_tree Visualizer.tree(self).to_s end