Sha256: 831fb10ca0f72fe12c1b62234c2415bf06cd1df908b77b4d15011499705fd91b
Contents?: true
Size: 1.76 KB
Versions: 22
Compression:
Stored size: 1.76 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! do |array| array.reject { |item| item.respond_to?(:empty?) && item.empty? } end 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
22 entries across 22 versions & 1 rubygems