Class: Coradoc::Mirror::ReverseBuilder::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/mirror/reverse_builder.rb

Overview

Base class for all reverse builders. Subclasses register one or more Mirror type strings via ‘registers` and implement `#build`. Shared helpers (build_content, extract_text, apply_mark, …) are delegated to the context (a MirrorToCoreModel instance), keeping each builder focused on the per-type mapping only (DRY).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Base

Returns a new instance of Base.



53
54
55
# File 'lib/coradoc/mirror/reverse_builder.rb', line 53

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



51
52
53
# File 'lib/coradoc/mirror/reverse_builder.rb', line 51

def context
  @context
end

Class Method Details

.registers(*types) ⇒ Object

DSL: declare which Mirror type strings this builder handles. Multiple strings per builder are allowed (e.g. all JS SECTION_TYPES route to the same SectionElement builder).



74
75
76
# File 'lib/coradoc/mirror/reverse_builder.rb', line 74

def registers(*types)
  types.each { |t| ReverseBuilder.register(t, self) }
end

Instance Method Details

#apply_mark(inner, mark) ⇒ Object



67
# File 'lib/coradoc/mirror/reverse_builder.rb', line 67

def apply_mark(inner, mark)     = context.apply_mark(inner, mark)

#build(_node) ⇒ Object

Raises:

  • (NotImplementedError)


57
58
59
60
# File 'lib/coradoc/mirror/reverse_builder.rb', line 57

def build(_node)
  raise NotImplementedError,
        "#{self.class} must implement #build(node)"
end

#build_content(node) ⇒ Object

Shared helpers — all delegate to the context (DRY).



63
# File 'lib/coradoc/mirror/reverse_builder.rb', line 63

def build_content(node) = context.build_content(node)

#build_inline_children(node) ⇒ Object



64
# File 'lib/coradoc/mirror/reverse_builder.rb', line 64

def build_inline_children(node) = context.build_inline_children(node)

#build_node(node) ⇒ Object



65
# File 'lib/coradoc/mirror/reverse_builder.rb', line 65

def build_node(node)            = context.build_node(node)

#extract_text(node) ⇒ Object



66
# File 'lib/coradoc/mirror/reverse_builder.rb', line 66

def extract_text(node)          = context.extract_text(node)

#inline_content(element) ⇒ Object



68
# File 'lib/coradoc/mirror/reverse_builder.rb', line 68

def inline_content(element)     = context.inline_content(element)