Class: TranslationDiff::Passage
- Inherits:
-
Object
- Object
- TranslationDiff::Passage
- Defined in:
- lib/translation_diff/passage.rb
Overview
A source document as markup and prose: the markup kept as found, the prose cut into segments a provider can take.
Defined Under Namespace
Classes: Scanner
Instance Attribute Summary collapse
-
#fragments ⇒ Object
readonly
Returns the value of attribute fragments.
Instance Method Summary collapse
-
#initialize(source, segmenter:, language: nil, opaque_elements: TranslationDiff.config.opaque_elements) ⇒ Passage
constructor
The source is scanned with every lone
<escaped, so the offsets, the slices and the render all agree on it. -
#render ⇒ Object
Entities are a segment's business, so the only thing left to undo here is the escape this class put in.
-
#segments ⇒ Object
The translatable sentences, in document order; the empty ones are whitespace a provider has no use for.
Constructor Details
#initialize(source, segmenter:, language: nil, opaque_elements: TranslationDiff.config.opaque_elements) ⇒ Passage
The source is scanned with every lone < escaped, so the offsets, the slices and the render all agree on it.
opaque_elements defaults to the live config, read here rather than memoised, so a runtime change takes effect
without a caller that only ever passes segmenter and language having to be touched.
8 9 10 11 12 13 |
# File 'lib/translation_diff/passage.rb', line 8 def initialize(source, segmenter:, language: nil, opaque_elements: TranslationDiff.config.opaque_elements) @source = TranslationDiff::Markup.(source) @segmenter = segmenter @language = language @fragments = Scanner.new(@source, opaque_elements: opaque_elements).runs.map { |run| fragment(run) } end |
Instance Attribute Details
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
3 4 5 |
# File 'lib/translation_diff/passage.rb', line 3 def fragments @fragments end |
Instance Method Details
#render ⇒ Object
Entities are a segment's business, so the only thing left to undo here is the escape this class put in.
19 20 21 |
# File 'lib/translation_diff/passage.rb', line 19 def render TranslationDiff::Markup.(fragments.map(&:render).join) end |
#segments ⇒ Object
The translatable sentences, in document order; the empty ones are whitespace a provider has no use for.
16 |
# File 'lib/translation_diff/passage.rb', line 16 def segments = fragments.flat_map(&:segments) |