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.
82 83 84 85 86 87 |
# File 'lib/text_alignment/char_mapping.rb', line 82 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.
80 81 82 |
# File 'lib/text_alignment/char_mapping.rb', line 80 def mapped_text @mapped_text end |
Instance Method Details
#demap_position(position) ⇒ Object
93 94 95 |
# File 'lib/text_alignment/char_mapping.rb', line 93 def demap_position(position) @index_demap[position] end |
#enmap_denotations(_denotations) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/text_alignment/char_mapping.rb', line 97 def enmap_denotations(_denotations) return nil if _denotations.nil? denotations = _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
89 90 91 |
# File 'lib/text_alignment/char_mapping.rb', line 89 def enmap_position(position) @index_enmap[position] end |