123456789_123456789_123456789_123456789_123456789_

Class: DidYouMean::ParseDimensions

Relationships & Source Files
Inherits: Object
Defined in: lib/did_you_mean/tree_spell_checker.rb

Overview

parses the elements in each dimension

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(dictionary, separator) ⇒ ParseDimensions

[ GitHub ]

  
# File 'lib/did_you_mean/tree_spell_checker.rb', line 79

def initialize(dictionary, separator)
  @dictionary = dictionary
  @separator = separator
end

Instance Attribute Details

#dictionary (readonly, private)

[ GitHub ]

  
# File 'lib/did_you_mean/tree_spell_checker.rb', line 112

attr_reader :dictionary, :separator

#separator (readonly, private)

[ GitHub ]

  
# File 'lib/did_you_mean/tree_spell_checker.rb', line 112

attr_reader :dictionary, :separator

Instance Method Details

#call

[ GitHub ]

  
# File 'lib/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

#find_elements(leafless) (private)

[ GitHub ]

  
# File 'lib/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 (private)

[ GitHub ]

  
# File 'lib/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