Class: Darjeelink::ShortLinkImporter
- Inherits:
-
Object
- Object
- Darjeelink::ShortLinkImporter
- Defined in:
- app/importers/darjeelink/short_link_importer.rb
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(path_to_csv) ⇒ ShortLinkImporter
constructor
A new instance of ShortLinkImporter.
Constructor Details
#initialize(path_to_csv) ⇒ ShortLinkImporter
Returns a new instance of ShortLinkImporter.
7 8 9 10 |
# File 'app/importers/darjeelink/short_link_importer.rb', line 7 def initialize(path_to_csv) @path_to_csv = path_to_csv @duplicates = [] end |
Instance Method Details
#import ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/importers/darjeelink/short_link_importer.rb', line 12 def import CSV.foreach(path_to_csv, headers: true).each do |row| url, auto_generated_key, custom_key = row.fields create_short_link(url, auto_generated_key, custom_key) end duplicate_string = duplicates.join("\n") Rails.logger.warn("Duplicates:\n#{duplicate_string}") unless duplicates.empty? end |