class ArticleFixtureGen::Data::BuildTargetEntryList
Builds a word list suitable for randomly selecting MTP locations; these may be used for either single- or paired-marker tag pairs by the simple expedient of reverse-sorting the returned list of entries. Existing MTPs in the content will be unaffected, as they will be treated as any other element node and, since they have no contained text, will not affect the result.
Attributes
chosen_indexes[R]
count[R]
parent_node[R]
Public Class Methods
call(parent_node, count)
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 14 def self.call(parent_node, count) new(parent_node, count).call end
new(parent_node, count)
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 24 def initialize(parent_node, count) @parent_node = parent_node @count = count @word_list = nil @chosen_indexes = [] self end
Public Instance Methods
call()
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 18 def call entries.sort.reverse end
Private Instance Methods
add_index(index)
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 36 def add_index(index) chosen_indexes << index index end
entries()
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 41 def entries Array.new(count) { item_from_word_list } end
index_taken?(index)
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 45 def index_taken?(index) return true if index.to_i.zero? # covers nil chosen_indexes.include?(index) end
item_from_word_list()
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 50 def item_from_word_list word_list[random_index] end
random_index()
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 54 def random_index add_index random_index_value end
random_index_value()
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 58 def random_index_value index = rand(word_list.count) while index_taken?(index) index end
word_list()
click to toggle source
# File lib/article_fixture_gen/data/build_target_entry_list.rb, line 63 def word_list @word_list ||= BuildWordList.call(parent_node: parent_node) end