Module: NanDoc::StreamColorizer::RuleList

Included in:
NanDoc::StreamColorizer, State
Defined in:
lib/nandoc/support/stream-colorizer.rb,
lib/nandoc/support/stream-colorizer.rb

Overview

api private classes:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rule_listObject (readonly)

Returns the value of attribute rule_list.



73
74
75
# File 'lib/nandoc/support/stream-colorizer.rb', line 73

def rule_list
  @rule_list
end

#state_setObject (readonly)

Returns the value of attribute state_set.



87
88
89
# File 'lib/nandoc/support/stream-colorizer.rb', line 87

def state_set
  @state_set
end

Instance Method Details

#add_regex_rule(re, opts) ⇒ Object



55
56
57
58
# File 'lib/nandoc/support/stream-colorizer.rb', line 55

def add_regex_rule re, opts
  fail("no") unless opts[:state]
  @rule_list.push RegexRule.make(re, opts[:state], {})
end

#add_regex_rule_neg(re, opts) ⇒ Object



59
60
61
62
# File 'lib/nandoc/support/stream-colorizer.rb', line 59

def add_regex_rule_neg re, opts
  fail("no") unless opts[:state]
  @rule_list.push RegexRule.make(re, opts[:state], {:neg=>true})
end

#define_state(name, &block) ⇒ Object



63
64
65
66
67
# File 'lib/nandoc/support/stream-colorizer.rb', line 63

def define_state name, &block
  state = State.new(self, name, &block)
  fail("no") if @state_set.key?(state.name)
  @state_set[state.name] = state
end

#get_state_or_fail(name) ⇒ Object



68
69
70
71
72
# File 'lib/nandoc/support/stream-colorizer.rb', line 68

def get_state_or_fail name
  state = @state_set[name]
  state or fail("no such state: #{name.inspect}")
  state
end

#rule_list_initObject



51
52
53
54
# File 'lib/nandoc/support/stream-colorizer.rb', line 51

def rule_list_init
  @rule_list = []
  @state_set = {}
end

#when(re_or_symbol, opts = nil, &block) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/nandoc/support/stream-colorizer.rb', line 74

def when(re_or_symbol, opts=nil, &block)
  if re_or_symbol.kind_of?(::Regexp) && Hash===opts && ! block_given?
    add_regex_rule(re_or_symbol, opts)
  elsif re_or_symbol.kind_of?(Symbol) && opts.nil? && block_given?
    define_state(re_or_symbol, &block)
  else
    fail("unrecongized signature: `#{self.class}#when("<<
      "[#{re_or_symbol.class}],[#{opts.class}],[#{block.class}])")
  end
end

#when_not(re, opts) ⇒ Object



84
85
86
# File 'lib/nandoc/support/stream-colorizer.rb', line 84

def when_not re, opts
  add_regex_rule_neg re, opts
end