Class: Coradoc::CoreModel::FrontmatterBlock::FieldTransform::Registry
- Inherits:
-
Object
- Object
- Coradoc::CoreModel::FrontmatterBlock::FieldTransform::Registry
- Defined in:
- lib/coradoc/core_model/frontmatter/field_transform.rb
Constant Summary collapse
- DEFAULT =
new
Instance Method Summary collapse
-
#apply_all(block, direction:, format:) ⇒ Object
Apply all registered transforms whose #applies? returns true.
- #count ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(transform_class) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
40 41 42 |
# File 'lib/coradoc/core_model/frontmatter/field_transform.rb', line 40 def initialize @transforms = [] end |
Instance Method Details
#apply_all(block, direction:, format:) ⇒ Object
Apply all registered transforms whose #applies? returns true. Returns a FrontmatterBlock (possibly the same one).
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/coradoc/core_model/frontmatter/field_transform.rb', line 54 def apply_all(block, direction:, format:) return block unless block.is_a?(FrontmatterBlock) @transforms.reduce(block) do |current, klass| transform = klass.new if transform.applies?(direction: direction, format: format) transform.apply(current) else current end end end |
#count ⇒ Object
48 49 50 |
# File 'lib/coradoc/core_model/frontmatter/field_transform.rb', line 48 def count @transforms.size end |
#register(transform_class) ⇒ Object
44 45 46 |
# File 'lib/coradoc/core_model/frontmatter/field_transform.rb', line 44 def register(transform_class) @transforms << transform_class unless @transforms.include?(transform_class) end |