From b3dcf1e0070e327f2a56dfd353a7167046a73b44 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Fri, 23 Apr 2021 19:03:27 -0400 Subject: [PATCH 1/2] Gemfile.lock --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index eaf817971..68df4cfb9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - kiba-extend (1.8.0) + kiba-extend (1.8.1) activesupport kiba (>= 4.0.0) kiba-common (>= 1.5.0) @@ -20,7 +20,7 @@ GEM concurrent-ruby (1.1.8) diff-lcs (1.3) facets (3.1.0) - i18n (1.8.9) + i18n (1.8.10) concurrent-ruby (~> 1.0) kiba (4.0.0) kiba-common (1.5.0) From 3e42565b70af18046c2518d78893cb2153c3722a Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Fri, 23 Apr 2021 19:03:50 -0400 Subject: [PATCH 2/2] add MsAccess::ScientificNotationToNumberString tranform --- lib/kiba/extend.rb | 1 + lib/kiba/extend/transforms/ms_access.rb | 31 +++++++++++++++++ lib/kiba/extend/version.rb | 2 +- spec/kiba/extend/transforms/ms_access_spec.rb | 33 +++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 lib/kiba/extend/transforms/ms_access.rb create mode 100644 spec/kiba/extend/transforms/ms_access_spec.rb diff --git a/lib/kiba/extend.rb b/lib/kiba/extend.rb index ba849eb75..7bf827965 100644 --- a/lib/kiba/extend.rb +++ b/lib/kiba/extend.rb @@ -25,6 +25,7 @@ module Extend require 'kiba/extend/transforms/explode' require 'kiba/extend/transforms/filter_rows' require 'kiba/extend/transforms/merge' + require 'kiba/extend/transforms/ms_access' require 'kiba/extend/transforms/prepend' require 'kiba/extend/transforms/rename' require 'kiba/extend/transforms/replace' diff --git a/lib/kiba/extend/transforms/ms_access.rb b/lib/kiba/extend/transforms/ms_access.rb new file mode 100644 index 000000000..abaa5c202 --- /dev/null +++ b/lib/kiba/extend/transforms/ms_access.rb @@ -0,0 +1,31 @@ +require 'bigdecimal' + +module Kiba + module Extend + module Transforms + module MsAccess + ::MsAccess = Kiba::Extend::Transforms::MsAccess + class ScientificNotationToNumberString + def initialize(fields:) + @fields = fields + end + + def process(row) + @fields.each{ |field| process_field(row, field) } + row + end + + private + + def process_field(row, field) + value = row[field] + return if value.blank? + return unless value.match?(/[Ee][-+]/) + row[field] = BigDecimal(value).to_s.sub(/\.0+$/, '') + #"%f" % value + end + end + end + end + end +end diff --git a/lib/kiba/extend/version.rb b/lib/kiba/extend/version.rb index 6adc71f63..d9ab9bdb7 100644 --- a/lib/kiba/extend/version.rb +++ b/lib/kiba/extend/version.rb @@ -1,5 +1,5 @@ module Kiba module Extend - VERSION = "1.8.1" + VERSION = "1.9.0" end end diff --git a/spec/kiba/extend/transforms/ms_access_spec.rb b/spec/kiba/extend/transforms/ms_access_spec.rb new file mode 100644 index 000000000..7717daad3 --- /dev/null +++ b/spec/kiba/extend/transforms/ms_access_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +RSpec.describe Kiba::Extend::Transforms::MsAccess do + describe 'ScientificNotationToNumberString' do + test_csv = 'tmp/test.csv' + rows = [ + ['id', 'width'], + [1, '1.70000000e+01'], + [2, '170'], + [3, ''], + [4, nil], + [5, '1.0e-10'] + ] + + before do + generate_csv(test_csv, rows) + end + it 'converts scientific notation value to number string' do + expected = [ + {id: '1', width: '17'}, + {id: '2', width: '170'}, + {id: '3', width: ''}, + {id: '4', width: nil}, + {id: '5', width: '0.0000000001'} + ] + result = execute_job(filename: test_csv, + xform: MsAccess::ScientificNotationToNumberString, + xformopt: {fields: %i[width]}) + expect(result).to eq(expected) + end + end +end +