Sha256: 182a3670db5152fe00df82f401e4e8589c0df2ced225e07da3da50d79ac31374
Contents?: true
Size: 1.72 KB
Versions: 10
Compression:
Stored size: 1.72 KB
Contents
# require "eitil_integrate/application_exporter/auto_sum/drop_data" module EitilIntegrate::RubyXL module AutoSum class << self def drop_data # since excel layout consistency requires stringified values, we first need # to convert strings back to floats. try_float_conversion # after the required conversions, drop all values that should not be accepted. drop_nil_values drop_empty_values drop_non_accepted_values end def try_float_conversion @hash.transform_values! { |array| array.map { |item| item.is_num? ? to_float(item) : item } } end def drop_nil_values @hash.transform_values! &:compact end def drop_empty_values @hash.transform_values! { |array| array.reject { |item| item.safe_send :empty? } } end def drop_non_accepted_values @hash.transform_values! { |array| array.reject { |item| !accepted_value? item } } end def accepted_value?(value) @value = value value_is_a_int || value_is_a_float || value_is_a_time_string end def to_float(object) # Implemented a new to_float method, which replaces .to_f, because "7.5".to_f # would correctly return 7.5, but "7,5" would incorrectly return 7.0. object.is_a?(String) ? object.gsub(',','.').to_f : object.to_f end def value_is_a_int @value.is_a? Integer end def value_is_a_float @value.is_a? Float end def value_is_a_time_string ( @value.scan(/^[A-Za-z]+/).blank? && @value.scan(/\d{2}:\d{2}:\d{2}/).first ) || ( @value.scan(/^[A-Za-z]+/).blank? && @value.scan(/\d{2}:\d{2}/).first ) end end end end
Version data entries
10 entries across 10 versions & 1 rubygems