class ArticleFixtureGen::Data::SplitTextAtTargetWord
Produces an array of two strings such that, for a specified text node (string), the first string will be the text before a specified word, and the second (last) string will be the text after that word. The word in question is specified by a child-node index relative to the `el` parameter (an `Ox::Element` instance) and a word index within that child node.
Attributes
original_text[R]
target_entry[R]
word_index[R]
Public Class Methods
call(el, target_entry)
click to toggle source
# File lib/article_fixture_gen/data/split_text_at_target_word.rb, line 11 def self.call(el, target_entry) new(el, target_entry).call end
new(el, target_entry)
click to toggle source
# File lib/article_fixture_gen/data/split_text_at_target_word.rb, line 21 def initialize(el, target_entry) @original_text = Internals.original_text(el, target_entry) @target_entry = target_entry @word_index = target_entry.word_index self end
Public Instance Methods
call()
click to toggle source
# File lib/article_fixture_gen/data/split_text_at_target_word.rb, line 15 def call [head, tail] end
Private Instance Methods
ends_in_space?()
click to toggle source
# File lib/article_fixture_gen/data/split_text_at_target_word.rb, line 32 def ends_in_space? original_text[-1] == ' ' end
head()
click to toggle source
# File lib/article_fixture_gen/data/split_text_at_target_word.rb, line 36 def head words_in_range(0...word_index) + ' ' end
tail()
click to toggle source
# File lib/article_fixture_gen/data/split_text_at_target_word.rb, line 40 def tail ret = words_in_range(word_index..-1) ret += ' ' if ends_in_space? ret end
words_in_range(range)
click to toggle source
# File lib/article_fixture_gen/data/split_text_at_target_word.rb, line 46 def words_in_range(range) original_text.split[range].join(' ') end