lib/array_hasher/formatter.rb in array_hasher-0.1.1 vs lib/array_hasher/formatter.rb in array_hasher-0.1.2
- old
+ new
@@ -5,13 +5,13 @@
attr_accessor :cols, :types
REGEXP_EMPTY = /\A\s*\z/
TYPES = {
- int: Proc.new {|v| v =~ REGEXP_EMPTY ? nil : v.gsub(/\A[^\d]+/, '').to_i },
- float: Proc.new {|v| v =~ REGEXP_EMPTY ? nil : v.gsub(/\A[^\d]+/, '').to_f },
+ int: Proc.new {|v| (v.nil? || v =~ REGEXP_EMPTY) ? nil : v.gsub(/\A[^\d]+/, '').to_i },
+ float: Proc.new {|v| (v.nil? || v =~ REGEXP_EMPTY) ? nil : v.gsub(/\A[^\d]+/, '').to_f },
string: Proc.new {|v| v.to_s },
- time: Proc.new {|v| Time.parse(v) }
+ time: Proc.new {|v| v ? Time.parse(v) : nil }
}
# cols:
# [
# [], # ignore this col