Module: Executrix::Helper
Constant Summary collapse
- CSV_OPTIONS =
{ col_sep: ',', quote_char: '"', force_quotes: true, }
Instance Method Summary collapse
- #absolute_to_relative_path(input, replacement) ⇒ Object
- #attachment_keys(records) ⇒ Object
- #fetch_instance_from_server_url(server_url) ⇒ Object
- #records_to_csv(records) ⇒ Object
- #transform_values!(records, keys) ⇒ Object
Instance Method Details
#absolute_to_relative_path(input, replacement) ⇒ Object
65 66 67 |
# File 'lib/executrix/helper.rb', line 65 def absolute_to_relative_path input, replacement input.gsub(/(^C:[\/\\])|(^\/)/,replacement) end |
#attachment_keys(records) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/executrix/helper.rb', line 41 def records records.map do |record| record.select do |key, value| value.class == File end.keys end.flatten.uniq end |
#fetch_instance_from_server_url(server_url) ⇒ Object
36 37 38 39 |
# File 'lib/executrix/helper.rb', line 36 def fetch_instance_from_server_url server_url before_sf = server_url[/^https?:\/\/(.+)\.salesforce\.com/, 1] before_sf.gsub(/-api$/,'') end |
#records_to_csv(records) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/executrix/helper.rb', line 13 def records_to_csv records file_mock = StringIO.new csv_client = CSV.new(file_mock, CSV_OPTIONS) all_headers = [] all_rows = [] records.each do |hash| row = CSV::Row.new([],[],false) to_store = hash.inject({}) do |h, (k, v)| h[k] = v.class == Array ? v.join(';') : v h end row << to_store all_headers << row.headers all_rows << row end all_headers.flatten!.uniq! csv_client << all_headers all_rows.each do |row| csv_client << row.fields(*all_headers) end file_mock.string end |
#transform_values!(records, keys) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/executrix/helper.rb', line 49 def transform_values! records, keys keys.each do |key| records.each do |record| file_handle = record[key] if file_handle file_path = File.absolute_path(file_handle) record .merge!({ key => Executrix::Helper.absolute_to_relative_path(file_path,'#') }) yield file_path if block_given? end end end end |