Class: TextAlignment::CharMapping
- Inherits:
-
Object
- Object
- TextAlignment::CharMapping
- Defined in:
- lib/text_alignment/char_mapping.rb
Instance Attribute Summary collapse
-
#mapped_text ⇒ Object
readonly
Returns the value of attribute mapped_text.
Instance Method Summary collapse
- #demap_position(position) ⇒ Object
- #enmap_denotations(denotations) ⇒ Object
- #enmap_position(position) ⇒ Object
-
#initialize(_text, char_mapping = nil) ⇒ CharMapping
constructor
A new instance of CharMapping.
Constructor Details
#initialize(_text, char_mapping = nil) ⇒ CharMapping
Returns a new instance of CharMapping.
83 84 85 86 87 88 |
# File 'lib/text_alignment/char_mapping.rb', line 83 def initialize(_text, char_mapping = nil) char_mapping ||= TextAlignment::CHAR_MAPPING @mapped_text, offset_mapping = enmap_text(_text, char_mapping) @index_enmap = offset_mapping.to_h @index_demap = offset_mapping.map{|m| m.reverse}.to_h end |
Instance Attribute Details
#mapped_text ⇒ Object (readonly)
Returns the value of attribute mapped_text.
81 82 83 |
# File 'lib/text_alignment/char_mapping.rb', line 81 def mapped_text @mapped_text end |
Instance Method Details
#demap_position(position) ⇒ Object
94 95 96 |
# File 'lib/text_alignment/char_mapping.rb', line 94 def demap_position(position) @index_demap[position] end |
#enmap_denotations(denotations) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/text_alignment/char_mapping.rb', line 98 def enmap_denotations(denotations) return nil if denotations.nil? denotations.map do |d| d.dup.merge(span:{begin:enmap_position(d[:span][:begin]), end:enmap_position(d[:span][:end])}) end end |
#enmap_position(position) ⇒ Object
90 91 92 |
# File 'lib/text_alignment/char_mapping.rb', line 90 def enmap_position(position) @index_enmap[position] end |