Module: Psychgus::Stylables::StyleStylable

Includes:
Psychgus::Styler
Included in:
MapFlowStylable, SeqFlowStylable
Defined in:
lib/psychgus/stylables.rb

Overview

A helper mixin for Stylables that change a node's style.

There is no max level, because a parent's style will override all of its children.

Since:

  • 1.2.0

Constant Summary

Constants included from Psychgus::Styler

Psychgus::Styler::EMPTY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Psychgus::Styler

#style, #style_alias, #style_document, #style_mapping, #style_scalar, #style_sequence, #style_stream

Instance Attribute Details

#min_levelInteger

Returns the minimum level (inclusive) to style.

Returns:

  • (Integer)

    the minimum level (inclusive) to style

Since:

  • 1.2.0



48
49
50
# File 'lib/psychgus/stylables.rb', line 48

def min_level
  @min_level
end

#new_styleInteger

Returns the new style to set the nodes to.

Returns:

  • (Integer)

    the new style to set the nodes to

Since:

  • 1.2.0



49
50
51
# File 'lib/psychgus/stylables.rb', line 49

def new_style
  @new_style
end

Instance Method Details

#change_style(sniffer, node) ⇒ Object

Change the style of node to #new_style if it is >= #min_level.

Since:

  • 1.2.0



62
63
64
65
66
# File 'lib/psychgus/stylables.rb', line 62

def change_style(sniffer,node)
  return unless node.respond_to?(:style=)
  
  node.style = @new_style if sniffer.level >= @min_level
end

#initialize(min_level = 0, new_style: nil, **kargs) ⇒ Object

max_level is not defined because a parent's style will override all of its children.

Parameters:

  • min_level (Integer) (defaults to: 0)

    the minimum level (inclusive) to style

  • new_style (Integer) (defaults to: nil)

    the new style to set the nodes to

  • kargs (Hash)

    capture extra keyword args, so no error for undefined args

Since:

  • 1.2.0



56
57
58
59
# File 'lib/psychgus/stylables.rb', line 56

def initialize(min_level=0,new_style: nil,**kargs)
  @min_level = min_level
  @new_style = new_style
end