Class: Nanoc3::Rule
- Inherits:
-
Object
- Object
- Nanoc3::Rule
- Defined in:
- lib/nanoc3/base/rule.rb
Overview
Contains the processing information for a item.
Instance Attribute Summary (collapse)
-
- (Regexp) identifier_regex
readonly
applied to.
-
- (Symbol) rep_name
readonly
using this rule.
Instance Method Summary (collapse)
-
- (Boolean) applicable_to?(item)
rep, false otherwise.
-
- (void) apply_to(rep)
Applies this rule to the given item rep.
-
- (Rule) initialize(identifier_regex, rep_name, block)
constructor
Creates a new item compilation rule with the given identifier regex, compiler and block.
Constructor Details
- (Rule) initialize(identifier_regex, rep_name, block)
Creates a new item compilation rule with the given identifier regex, compiler and block. The block will be called during compilation with the item rep as its argument.
to determine whether this rule is applicable to certain items.
where this rule can be applied to
compiled
29 30 31 32 33 34 |
# File 'lib/nanoc3/base/rule.rb', line 29 def initialize(identifier_regex, rep_name, block) @identifier_regex = identifier_regex @rep_name = rep_name.to_sym @block = block end |
Instance Attribute Details
- (Regexp) identifier_regex (readonly)
applied to. This rule can be applied to items with a identifier matching this regex.
11 12 13 |
# File 'lib/nanoc3/base/rule.rb', line 11 def identifier_regex @identifier_regex end |
- (Symbol) rep_name (readonly)
using this rule
15 16 17 |
# File 'lib/nanoc3/base/rule.rb', line 15 def rep_name @rep_name end |
Instance Method Details
- (Boolean) applicable_to?(item)
rep, false otherwise
40 41 42 |
# File 'lib/nanoc3/base/rule.rb', line 40 def applicable_to?(item) item.identifier =~ @identifier_regex end |
- (void) apply_to(rep)
This method returns an undefined value.
Applies this rule to the given item rep.
should be applied to
50 51 52 |
# File 'lib/nanoc3/base/rule.rb', line 50 def apply_to(rep) Nanoc3::RuleContext.new(rep).instance_eval &@block end |