Module: Psychgus::Stylables::HierarchyStylable
- Includes:
- Psychgus::Styler
- Included in:
- Psychgus::Stylers::HierarchyStyler
- Defined in:
- lib/psychgus/stylables.rb
Overview
A visual hierarchy writer of the levels.
This is useful for determining the correct level/position when writing a Psychgus::Styler.
The default IO is StringIO, but can specify a different one.
See Psychgus.hierarchy for more details.
Constant Summary
Constants included from Psychgus::Styler
Instance Attribute Summary collapse
-
#io ⇒ IO
The IO to write to; defaults to StringIO.
-
#verbose ⇒ true, false
Whether to be more verbose (e.g., write child info).
Instance Method Summary collapse
- #initialize(io: StringIO.new, verbose: false, **kargs) ⇒ Object
-
#style(sniffer, node) ⇒ Object
Write the hierarchy of
node
to #io. -
#to_s ⇒ String
Convert #io to a String if possible (e.g., StringIO).
Methods included from Psychgus::Styler
#style_alias, #style_document, #style_mapping, #style_scalar, #style_sequence, #style_stream
Instance Attribute Details
#io ⇒ IO
Returns the IO to write to; defaults to StringIO.
125 126 127 |
# File 'lib/psychgus/stylables.rb', line 125 def io @io end |
#verbose ⇒ true, false
Returns whether to be more verbose (e.g., write child info).
126 127 128 |
# File 'lib/psychgus/stylables.rb', line 126 def verbose @verbose end |
Instance Method Details
#initialize(io: StringIO.new, verbose: false, **kargs) ⇒ Object
131 132 133 134 |
# File 'lib/psychgus/stylables.rb', line 131 def initialize(io: StringIO.new,verbose: false,**kargs) @io = io @verbose = verbose end |
#style(sniffer, node) ⇒ Object
Write the hierarchy of node
to #io.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/psychgus/stylables.rb', line 139 def style(sniffer,node) @io.print(' ' * (sniffer.level - 1)) name = node.respond_to?(:value) ? node.value : node.class.name parent = sniffer.parent @io.print "(#{sniffer.level}:#{sniffer.position}):#{name} - " if @verbose @io.print parent else @io.print "<#{parent.debug_tag}:(#{parent.level}:#{parent.position})>" end @io.puts end |
#to_s ⇒ String
Convert #io to a String if possible (e.g., StringIO).
159 160 161 |
# File 'lib/psychgus/stylables.rb', line 159 def to_s return @io.respond_to?(:string) ? @io.string : @io.to_s end |