Class: Furigana::Formatter::Base
- Inherits:
-
Object
- Object
- Furigana::Formatter::Base
- Defined in:
- lib/furigana/formatter/base.rb
Instance Method Summary collapse
-
#initialize(text, kanji_tokens) ⇒ Base
constructor
A new instance of Base.
- #render ⇒ Object
Constructor Details
#initialize(text, kanji_tokens) ⇒ Base
Returns a new instance of Base.
6 7 8 9 |
# File 'lib/furigana/formatter/base.rb', line 6 def initialize(text, kanji_tokens) @text = text @kanji_tokens = kanji_tokens end |
Instance Method Details
#render ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/furigana/formatter/base.rb', line 11 def render reset @text.each_char do |char| if no_more_kanji_tokens? @new_text += char next end @substring += char if not_a_kanji_group_match? char @new_text += @substring reset_substring next end if kanji_group_match? # replace kanji group with formatting @new_text += replacement(@current_token[SURFACE_FORM], @current_token[READING]) @current_token = next_token reset_substring else # kanji token pos advances with char pos increment_kanji_char_pos end end @new_text end |