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.
140 141 142 |
# File 'lib/psychgus/stylables.rb', line 140 def io @io end |
#verbose ⇒ true, false
Returns whether to be more verbose (e.g., write child info).
141 142 143 |
# File 'lib/psychgus/stylables.rb', line 141 def verbose @verbose end |
Instance Method Details
#initialize(io: StringIO.new(), verbose: false, **kargs) ⇒ Object
146 147 148 149 |
# File 'lib/psychgus/stylables.rb', line 146 def initialize(io: StringIO.new(),verbose: false,**kargs) @io = io @verbose = verbose end |
#style(sniffer, node) ⇒ Object
Write the hierarchy of node
to #io.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/psychgus/stylables.rb', line 154 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).
174 175 176 |
# File 'lib/psychgus/stylables.rb', line 174 def to_s() return @io.respond_to?(:string) ? @io.string : @io.to_s() end |