class Punctuation
Attributes
result[R]
Public Class Methods
new(result)
click to toggle source
# File lib/punctuation.rb, line 6 def initialize(result) @result = result end
Public Instance Methods
call()
click to toggle source
# File lib/punctuation.rb, line 10 def call check_punctuation check_special_character end
Private Instance Methods
check_punctuation()
click to toggle source
# File lib/punctuation.rb, line 17 def check_punctuation result.each_with_index do |val, index| if Config::PUNCTUATION.flatten.include?(val) # punctuation = [[';',':','!','?'],['.',',','...']] index = result.index(val) word = return_word_with_space_or_not(val, index) result[index].insert(0, word) result.delete(result[index-1]) end end end
check_special_character()
click to toggle source
# File lib/punctuation.rb, line 36 def check_special_character result.each_with_index do |val, index| if Config::SPECIAL_CHARACTER.include?(val) index = result.index(val) word = [result[index-1], result[index], result[index+1]] delete_useless_value(word, index) result.insert(index-1, word.join('')) end end end
delete_useless_value(word, index)
click to toggle source
# File lib/punctuation.rb, line 47 def delete_useless_value(word, index) word.each do |a| index_to_delete = result.index(a) result.delete_at(index_to_delete) end end
return_word_with_space_or_not(val, index)
click to toggle source
# File lib/punctuation.rb, line 28 def return_word_with_space_or_not(val, index) if Config::PUNCTUATION[0].include?(val) result[index-1] + ' ' else result[index-1] end end