Class: NanDoc::StreamColorizer
- Inherits:
-
Object
- Object
- NanDoc::StreamColorizer
- Includes:
- RuleList
- Defined in:
- lib/nandoc/support/stream-colorizer.rb
Defined Under Namespace
Modules: RuleList, SecretParent Classes: RegexRule, RegexRuleNeg, State
Instance Attribute Summary collapse
-
#rule_list ⇒ Object
writeonly
Sets the attribute rule_list.
-
#state_set ⇒ Object
writeonly
Sets the attribute state_set.
-
#stylesheet ⇒ Object
Returns the value of attribute stylesheet.
Attributes included from RuleList
Instance Method Summary collapse
- #dup ⇒ Object
- #filter(string, out) ⇒ Object
-
#initialize(*a, &b) ⇒ StreamColorizer
constructor
A new instance of StreamColorizer.
- #merge {|_self| ... } ⇒ Object
- #spawn(*a, &b) ⇒ Object
- #stylesheet_merge(other) ⇒ Object
Methods included from RuleList
#add_regex_rule, #add_regex_rule_neg, #define_state, #get_state_or_fail, #rule_list_init, #when, #when_not
Constructor Details
#initialize(*a, &b) ⇒ StreamColorizer
Returns a new instance of StreamColorizer.
13 14 15 16 17 18 19 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 13 def initialize(*a, &b) rule_list_init @stylesheet = {} if a.any? || block_given? merge(*a, &b) end end |
Instance Attribute Details
#rule_list=(value) ⇒ Object (writeonly)
Sets the attribute rule_list
20 21 22 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 20 def rule_list=(value) @rule_list = value end |
#state_set=(value) ⇒ Object (writeonly)
Sets the attribute state_set
40 41 42 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 40 def state_set=(value) @state_set = value end |
#stylesheet ⇒ Object
Returns the value of attribute stylesheet.
41 42 43 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 41 def stylesheet @stylesheet end |
Instance Method Details
#dup ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 6 def dup other = self.class.new other.stylesheet = stylesheet.dup other.rule_list = rule_list.dup other.state_set = state_set.dup other end |
#filter(string, out) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 21 def filter string, out found = rule_list.detect{ |x| x.match(string) } use_state = found ? found.state : :plain state = get_state_or_fail(use_state) string = string.dup while next_state_name = state.process(string, out) state = get_state_or_fail(next_state_name) end nil end |
#merge {|_self| ... } ⇒ Object
31 32 33 34 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 31 def merge(&block) yield(self) if block_given? self end |
#spawn(*a, &b) ⇒ Object
35 36 37 38 39 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 35 def spawn(*a, &b) other = dup other.merge(*a, &b) other end |
#stylesheet_merge(other) ⇒ Object
42 43 44 |
# File 'lib/nandoc/support/stream-colorizer.rb', line 42 def stylesheet_merge other @stylesheet.merge!(other) end |