Created
June 26, 2019 12:54
-
-
Save mjacobus/476e0f399cecf4a7349d34d1cece5d2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'csv' | |
| class Entry | |
| attr_reader :row | |
| def initialize(row) | |
| @row = row | |
| end | |
| def name | |
| row['Nome'] || email | |
| end | |
| def email | |
| row['Email'] | |
| end | |
| def phone | |
| row['Celular'] | |
| end | |
| def id | |
| row['ID'] | |
| end | |
| def time | |
| Time.now | |
| end | |
| def formatted_phone | |
| if phone.to_s == '' | |
| return | |
| end | |
| parts = phone.to_s.split('-') | |
| "+#{parts[0]} #{parts[1]}" | |
| end | |
| end | |
| entries = [] | |
| CSV.foreach('input.csv', headers: true, col_sep: ';') do |row| | |
| entries.push(Entry.new(row.to_h)) | |
| end | |
| def template(entry) | |
| <<~STRING | |
| BEGIN:VCARD | |
| VERSION:3.0 | |
| N:#{entry.name};Formula;;; | |
| FN:#{entry.name} | |
| ORG:Fórmula; | |
| TEL;type=CELL;type=VOICE;type=pref:#{entry.formatted_phone} | |
| NOTE: Exported by marcelo on #{entry.time} | |
| REV:#{entry.time} | |
| UID:#{entry.id} | |
| END:VCARD | |
| STRING | |
| end | |
| file = '/home/marcelo/Downloads/export_formula.vcf' | |
| # entries = [ entries.find{|e| e.id == 'ce3c6c380f'}] | |
| File.open(file, 'w') do |f| | |
| entries.each do |entry| | |
| f.puts(template(entry)) | |
| end | |
| end | |
| puts File.read(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment