class EmtApi::Parser
Public Class Methods
add_spaces_between_separators(sentence)
click to toggle source
# File lib/emt_api/parser.rb, line 19 def self.add_spaces_between_separators(sentence) spaced_sentence = sentence # Add space before the '-' character spaced_sentence.gsub!(/(?!\s)\-/, ' -') # Add space after the '-' character spaced_sentence.gsub!(/\-(?!\s)/, '- ') # Add space after the '.' used for abbreviations spaced_sentence.gsub!(/\.(?!\s)/, '. ') spaced_sentence end
capitalize_sentence(sentence)
click to toggle source
# File lib/emt_api/parser.rb, line 34 def self.capitalize_sentence(sentence) sentence.split.map { |word| word.capitalize }.join(' ') end
parse_date(date_string)
click to toggle source
# File lib/emt_api/parser.rb, line 4 def self.parse_date(date_string) date_string = remove_trailing_whitespaces(date_string) Date.parse(date_string) end
parse_sentence(sentence)
click to toggle source
# File lib/emt_api/parser.rb, line 9 def self.parse_sentence(sentence) sentence = remove_trailing_whitespaces(sentence) sentence = add_spaces_between_separators(sentence) capitalize_sentence(sentence) end
remove_trailing_whitespaces(sentence)
click to toggle source
# File lib/emt_api/parser.rb, line 15 def self.remove_trailing_whitespaces(sentence) sentence.rstrip end