Sha256: 6677bd3070f08f3ab1eba99f9e3d9bf5168e81f3d41ec8a1b7fbf540508380bb
Contents?: true
Size: 767 Bytes
Versions: 1
Compression:
Stored size: 767 Bytes
Contents
class Array # Map booleans true to 1 and false to 0 so they can be compared in a sort # with the <=> operator. def map_booleans map do |v| if v == true 1 elsif v == false 0 else v end end end def filter_to_type(typ) if typ == 'Boolean' compact.select { |i| i.is_a?(TrueClass) || i.is_a?(FalseClass) } elsif typ == 'DateTime' compact.select { |i| i.is_a?(Date) || i.is_a?(DateTime) || i.is_a?(Time) } .map(&:to_datetime) elsif typ == 'Numeric' compact.select { |i| i.is_a?(Numeric) } elsif typ == 'String' map(&:to_s) elsif typ == 'NilClass' self else raise ArgumentError, "cannot filter_to_type for type '#{typ}'" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fat_table-0.9.8 | lib/ext/array.rb |