Module: KindleNotebook::Helpers
- Defined in:
- lib/kindle_notebook/helpers.rb
Class Method Summary collapse
- .clean_up_text(text) ⇒ Object
- .sentence_with_word(full_text, target_word) ⇒ Object
- .to_csv_file(headers, list, file_name = "output.csv") ⇒ Object
Class Method Details
.clean_up_text(text) ⇒ Object
19 20 21 |
# File 'lib/kindle_notebook/helpers.rb', line 19 def self.clean_up_text(text) text.downcase.gsub(/[^0-9a-zA-Z -]+/, "").strip end |
.sentence_with_word(full_text, target_word) ⇒ Object
13 14 15 16 17 |
# File 'lib/kindle_notebook/helpers.rb', line 13 def self.sentence_with_word(full_text, target_word) sentences = full_text.scan(/\s+[^.!?]*[.!?]/) # match sentences matching_sentence = sentences.select { |s| s.include?(target_word) }.first&.strip matching_sentence || full_text end |
.to_csv_file(headers, list, file_name = "output.csv") ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/kindle_notebook/helpers.rb', line 5 def self.to_csv_file(headers, list, file_name = "output.csv") full_csv = "" full_csv += CSV.generate_line(headers) list.each { |element| full_csv += element.to_csv } File.write(file_name, full_csv) file_name end |