class DidYouMean::ParseDimensions

parses the elements in each dimension

Attributes

dictionary[R]
separator[R]

Public Class Methods

new(dictionary, separator) click to toggle source
# File did_you_mean/tree_spell_checker.rb, line 79
def initialize(dictionary, separator)
  @dictionary = dictionary
  @separator = separator
end

Public Instance Methods

call() click to toggle source
# File did_you_mean/tree_spell_checker.rb, line 84
def call
  leafless = remove_leaves
  dimensions = find_elements leafless
  dimensions.map do |elements|
    elements.to_set.to_a
  end
end

Private Instance Methods

find_elements(leafless) click to toggle source
# File did_you_mean/tree_spell_checker.rb, line 101
def find_elements(leafless)
  max_elements = leafless.map(&:size).max
  dimensions = Array.new(max_elements) { [] }
  (0...max_elements).each do |i|
    leafless.each do |elements|
      dimensions[i] << elements[i] unless elements[i].nil?
    end
  end
  dimensions
end
remove_leaves() click to toggle source
# File did_you_mean/tree_spell_checker.rb, line 94
def remove_leaves
  dictionary.map do |a|
    elements = a.split(separator)
    elements[0..-2]
  end.to_set.to_a
end