flat_kit 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -2
- data/HISTORY.md +9 -0
- data/Manifest.txt +3 -42
- data/{bin → exe}/fk +2 -1
- data/flat_kit.gemspec +33 -0
- data/lib/flat_kit/cli.rb +46 -32
- data/lib/flat_kit/command/cat.rb +34 -32
- data/lib/flat_kit/command/merge.rb +37 -36
- data/lib/flat_kit/command/sort.rb +37 -37
- data/lib/flat_kit/command/stats.rb +41 -39
- data/lib/flat_kit/command.rb +10 -11
- data/lib/flat_kit/descendant_tracker.rb +9 -6
- data/lib/flat_kit/error.rb +4 -0
- data/lib/flat_kit/event_emitter.rb +5 -2
- data/lib/flat_kit/field_stats.rb +31 -26
- data/lib/flat_kit/field_type/boolean_type.rb +9 -5
- data/lib/flat_kit/field_type/date_type.rb +19 -17
- data/lib/flat_kit/field_type/float_type.rb +15 -9
- data/lib/flat_kit/field_type/guess_type.rb +9 -6
- data/lib/flat_kit/field_type/integer_type.rb +6 -4
- data/lib/flat_kit/field_type/null_type.rb +5 -1
- data/lib/flat_kit/field_type/string_type.rb +8 -6
- data/lib/flat_kit/field_type/timestamp_type.rb +11 -10
- data/lib/flat_kit/field_type/unknown_type.rb +12 -8
- data/lib/flat_kit/field_type.rb +52 -44
- data/lib/flat_kit/format.rb +11 -5
- data/lib/flat_kit/input/file.rb +11 -9
- data/lib/flat_kit/input/io.rb +18 -21
- data/lib/flat_kit/input.rb +8 -7
- data/lib/flat_kit/internal_node.rb +22 -19
- data/lib/flat_kit/jsonl/format.rb +6 -2
- data/lib/flat_kit/jsonl/reader.rb +7 -4
- data/lib/flat_kit/jsonl/record.rb +15 -18
- data/lib/flat_kit/jsonl/writer.rb +8 -10
- data/lib/flat_kit/jsonl.rb +8 -4
- data/lib/flat_kit/leaf_node.rb +6 -5
- data/lib/flat_kit/log_formatter.rb +20 -0
- data/lib/flat_kit/logger.rb +12 -19
- data/lib/flat_kit/merge.rb +21 -18
- data/lib/flat_kit/merge_tree.rb +5 -6
- data/lib/flat_kit/output/file.rb +13 -9
- data/lib/flat_kit/output/io.rb +40 -35
- data/lib/flat_kit/output.rb +8 -7
- data/lib/flat_kit/position.rb +3 -4
- data/lib/flat_kit/reader.rb +8 -8
- data/lib/flat_kit/record.rb +12 -12
- data/lib/flat_kit/sentinel_internal_node.rb +6 -5
- data/lib/flat_kit/sentinel_leaf_node.rb +4 -1
- data/lib/flat_kit/sort.rb +8 -9
- data/lib/flat_kit/stat_type/nominal_stats.rb +13 -7
- data/lib/flat_kit/stat_type/numerical_stats.rb +18 -18
- data/lib/flat_kit/stat_type/ordinal_stats.rb +8 -13
- data/lib/flat_kit/stat_type.rb +18 -13
- data/lib/flat_kit/stats.rb +12 -14
- data/lib/flat_kit/writer.rb +5 -6
- data/lib/flat_kit/xsv/format.rb +6 -2
- data/lib/flat_kit/xsv/reader.rb +8 -6
- data/lib/flat_kit/xsv/record.rb +21 -15
- data/lib/flat_kit/xsv/writer.rb +13 -10
- data/lib/flat_kit/xsv.rb +7 -4
- data/lib/flat_kit.rb +31 -26
- metadata +20 -158
- data/Rakefile +0 -21
- data/examples/stream-active-record-to-csv.rb +0 -42
- data/tasks/default.rake +0 -242
- data/tasks/extension.rake +0 -38
- data/tasks/man.rake +0 -7
- data/tasks/this.rb +0 -208
- data/test/device_dataset.rb +0 -117
- data/test/field_type/test_boolean_type.rb +0 -65
- data/test/field_type/test_date_type.rb +0 -71
- data/test/field_type/test_float_type.rb +0 -56
- data/test/field_type/test_guess_type.rb +0 -14
- data/test/field_type/test_integer_type.rb +0 -52
- data/test/field_type/test_null_type.rb +0 -41
- data/test/field_type/test_string_type.rb +0 -18
- data/test/field_type/test_timestamp_type.rb +0 -108
- data/test/field_type/test_unknown_type.rb +0 -35
- data/test/input/test_file.rb +0 -73
- data/test/input/test_io.rb +0 -93
- data/test/jsonl/test_format.rb +0 -22
- data/test/jsonl/test_reader.rb +0 -49
- data/test/jsonl/test_record.rb +0 -61
- data/test/jsonl/test_writer.rb +0 -86
- data/test/output/test_file.rb +0 -60
- data/test/output/test_io.rb +0 -104
- data/test/run +0 -23
- data/test/stat_type/test_nominal_stats.rb +0 -69
- data/test/stat_type/test_numerical_stats.rb +0 -118
- data/test/stat_type/test_ordinal_stats.rb +0 -92
- data/test/test_conversions.rb +0 -45
- data/test/test_event_emitter.rb +0 -89
- data/test/test_field_stats.rb +0 -134
- data/test/test_field_type.rb +0 -34
- data/test/test_format.rb +0 -24
- data/test/test_helper.rb +0 -26
- data/test/test_merge.rb +0 -40
- data/test/test_merge_tree.rb +0 -64
- data/test/test_version.rb +0 -11
- data/test/xsv/test_format.rb +0 -22
- data/test/xsv/test_reader.rb +0 -61
- data/test/xsv/test_record.rb +0 -69
- data/test/xsv/test_writer.rb +0 -89
data/tasks/this.rb
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
# Public: A Class containing all the metadata and utilities needed to manage a
|
4
|
-
# ruby project.
|
5
|
-
class ThisProject
|
6
|
-
# The name of this project
|
7
|
-
attr_accessor :name
|
8
|
-
|
9
|
-
# The author's name
|
10
|
-
attr_accessor :author
|
11
|
-
|
12
|
-
# The email address of the author(s)
|
13
|
-
attr_accessor :email
|
14
|
-
|
15
|
-
# The homepage of this project
|
16
|
-
attr_accessor :homepage
|
17
|
-
|
18
|
-
# The regex of files to exclude from the manifest
|
19
|
-
attr_accessor :exclude_from_manifest
|
20
|
-
|
21
|
-
# The hash of Gem::Specifications keyed' by platform
|
22
|
-
attr_accessor :gemspecs
|
23
|
-
|
24
|
-
# Public: Initialize ThisProject
|
25
|
-
#
|
26
|
-
# Yields self
|
27
|
-
def initialize(&block)
|
28
|
-
@exclude_from_manifest = Regexp.union(/\.(git|DS_Store)/,
|
29
|
-
/^(doc|coverage|pkg|tmp|Gemfile(\.lock)?)/,
|
30
|
-
/^[^\/]+\.gemspec/,
|
31
|
-
/\.(swp|jar|bundle|so|rvmrc|travis.yml|byebug_history|fossa.yml|ruby-version)$/,
|
32
|
-
/~$/)
|
33
|
-
@gemspecs = Hash.new
|
34
|
-
yield self if block_given?
|
35
|
-
end
|
36
|
-
|
37
|
-
# Public: return the version of ThisProject
|
38
|
-
#
|
39
|
-
# Search the ruby files in the project looking for the one that has the
|
40
|
-
# version string in it. This does not eval any code in the project, it parses
|
41
|
-
# the source code looking for the string.
|
42
|
-
#
|
43
|
-
# Returns a String version
|
44
|
-
def version
|
45
|
-
[ "lib/#{ name }.rb", "lib/#{ name }/version.rb" ].each do |v|
|
46
|
-
path = project_path( v )
|
47
|
-
line = path.read[/^\s*VERSION\s*=\s*.*/]
|
48
|
-
if line then
|
49
|
-
return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Internal: Return a section of an RDoc file with the given section name
|
55
|
-
#
|
56
|
-
# path - the relative path in the project of the file to parse
|
57
|
-
# section_name - the section out of the file from which to parse data
|
58
|
-
#
|
59
|
-
# Retuns the text of the section as an array of paragrphs.
|
60
|
-
def section_of( file, section_name )
|
61
|
-
re = /^[=#]+ (.*)$/
|
62
|
-
sectional = project_path( file )
|
63
|
-
parts = sectional.read.split( re )[1..-1]
|
64
|
-
parts.map! { |p| p.strip }
|
65
|
-
|
66
|
-
sections = Hash.new
|
67
|
-
Hash[*parts].each do |k,v|
|
68
|
-
sections[k] = v.split("\n\n")
|
69
|
-
end
|
70
|
-
return sections[section_name]
|
71
|
-
end
|
72
|
-
|
73
|
-
# Internal: print out a warning about the give task
|
74
|
-
def task_warning( task )
|
75
|
-
warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
|
76
|
-
end
|
77
|
-
|
78
|
-
# Internal: Return the full path to the file that is relative to the project
|
79
|
-
# root.
|
80
|
-
#
|
81
|
-
# path - the relative path of the file from the project root
|
82
|
-
#
|
83
|
-
# Returns the Pathname of the file
|
84
|
-
def project_path( *relative_path )
|
85
|
-
project_root.join( *relative_path )
|
86
|
-
end
|
87
|
-
|
88
|
-
# Internal: The absolute path of this file
|
89
|
-
#
|
90
|
-
# Returns the Pathname of this file.
|
91
|
-
def this_file_path
|
92
|
-
Pathname.new( __FILE__ ).expand_path
|
93
|
-
end
|
94
|
-
|
95
|
-
# Internal: The root directory of this project
|
96
|
-
#
|
97
|
-
# This is defined as being the directory that is in the path of this project
|
98
|
-
# that has the first Rakefile
|
99
|
-
#
|
100
|
-
# Returns the Pathname of the directory
|
101
|
-
def project_root
|
102
|
-
this_file_path.ascend do |p|
|
103
|
-
rakefile = p.join( 'Rakefile' )
|
104
|
-
return p if rakefile.exist?
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Internal: Returns the contents of the Manifest.txt file as an array
|
109
|
-
#
|
110
|
-
# Returns an Array of strings
|
111
|
-
def manifest
|
112
|
-
manifest_file = project_path( "Manifest.txt" )
|
113
|
-
abort "You need a Manifest.txt" unless manifest_file.readable?
|
114
|
-
manifest_file.readlines.map { |l| l.strip }
|
115
|
-
end
|
116
|
-
|
117
|
-
# Internal: Return the files that define the extensions
|
118
|
-
#
|
119
|
-
# Returns an Array
|
120
|
-
def extension_conf_files
|
121
|
-
manifest.grep( /extconf.rb\Z/ )
|
122
|
-
end
|
123
|
-
|
124
|
-
# Internal: Returns the gemspace associated with the current ruby platform
|
125
|
-
def platform_gemspec
|
126
|
-
gemspecs.fetch(platform) { This.ruby_gemspec }
|
127
|
-
end
|
128
|
-
|
129
|
-
def core_gemspec
|
130
|
-
Gem::Specification.new do |spec|
|
131
|
-
spec.name = name
|
132
|
-
spec.version = version
|
133
|
-
spec.author = author
|
134
|
-
spec.email = email
|
135
|
-
spec.homepage = homepage
|
136
|
-
|
137
|
-
spec.summary = summary
|
138
|
-
spec.description = description
|
139
|
-
spec.license = license
|
140
|
-
|
141
|
-
spec.files = manifest
|
142
|
-
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
|
143
|
-
spec.test_files = spec.files.grep(/^(spec|test)/)
|
144
|
-
|
145
|
-
spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc|md)$/)
|
146
|
-
spec.rdoc_options = [ "--main" , 'README.md',
|
147
|
-
"--markup", "tomdoc" ]
|
148
|
-
|
149
|
-
spec.required_ruby_version = '>= 2.2.2'
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# Internal: Return the gemspec for the ruby platform
|
154
|
-
def ruby_gemspec( core = core_gemspec, &block )
|
155
|
-
yielding_gemspec( 'ruby', core, &block )
|
156
|
-
end
|
157
|
-
|
158
|
-
# Internal: Return the gemspec for the jruby platform
|
159
|
-
def java_gemspec( core = core_gemspec, &block )
|
160
|
-
yielding_gemspec( 'java', core, &block )
|
161
|
-
end
|
162
|
-
|
163
|
-
# Internal: give an initial spec and a key, create a new gemspec based off of
|
164
|
-
# it.
|
165
|
-
#
|
166
|
-
# This will force the new gemspecs 'platform' to be that of the key, since the
|
167
|
-
# only reason you would have multiple gemspecs at this point is to deal with
|
168
|
-
# different platforms.
|
169
|
-
def yielding_gemspec( key, core )
|
170
|
-
spec = gemspecs[key] ||= core.dup
|
171
|
-
spec.platform = key
|
172
|
-
yield spec if block_given?
|
173
|
-
return spec
|
174
|
-
end
|
175
|
-
|
176
|
-
# Internal: Return the platform of ThisProject at the current moment in time.
|
177
|
-
def platform
|
178
|
-
(RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
|
179
|
-
end
|
180
|
-
|
181
|
-
# Internal: Return the DESCRIPTION section of the README.rdoc file
|
182
|
-
def description_section
|
183
|
-
section_of( 'README.md', 'DESCRIPTION')
|
184
|
-
end
|
185
|
-
|
186
|
-
# Internal: Return the summary text from the README
|
187
|
-
def summary
|
188
|
-
description_section.first
|
189
|
-
end
|
190
|
-
|
191
|
-
# Internal: Return the full description text from the README
|
192
|
-
def description
|
193
|
-
description_section.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
|
194
|
-
end
|
195
|
-
|
196
|
-
def license
|
197
|
-
license_file = project_path("LICENSE.txt")
|
198
|
-
line = license_file.readlines.first
|
199
|
-
line.split(/\s+/).first
|
200
|
-
end
|
201
|
-
|
202
|
-
# Internal: The path to the gemspec file
|
203
|
-
def gemspec_file
|
204
|
-
project_path( "#{ name }.gemspec" )
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
This = ThisProject.new
|
data/test/device_dataset.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
class DeviceDataset
|
2
|
-
|
3
|
-
include TestHelper
|
4
|
-
|
5
|
-
attr_reader :count
|
6
|
-
attr_reader :compare_fields
|
7
|
-
attr_reader :fields
|
8
|
-
|
9
|
-
attr_reader :filename_jsonl
|
10
|
-
attr_reader :filename_sorted_jsonl
|
11
|
-
attr_reader :filename_csv
|
12
|
-
attr_reader :filename_sorted_csv
|
13
|
-
|
14
|
-
def initialize(count:, compare_fields: [ "manufacturer", "model_name", "slug" ])
|
15
|
-
@count = count
|
16
|
-
@compare_fields = compare_fields
|
17
|
-
@fields = %w[
|
18
|
-
build_number
|
19
|
-
manufacturer
|
20
|
-
model_name
|
21
|
-
platform
|
22
|
-
serial
|
23
|
-
slug
|
24
|
-
]
|
25
|
-
@filename_sorted_jsonl = nil
|
26
|
-
@filename_jsonl = nil
|
27
|
-
@filename_sorted_csv = nil
|
28
|
-
@filename_csv = nil
|
29
|
-
@slug = generate_slug
|
30
|
-
end
|
31
|
-
|
32
|
-
def persist_records_as_jsonl
|
33
|
-
@filename_jsonl = scratch_file(prefix: "unsorted_", slug: @slug)
|
34
|
-
@filename_jsonl.open("w+") do |f|
|
35
|
-
f.write(records_as_jsonl)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def persist_sorted_records_as_jsonl
|
40
|
-
@filename_sorted_jsonl = scratch_file(prefix: "sorted_", slug: @slug)
|
41
|
-
@filename_sorted_jsonl.open("w+") do |f|
|
42
|
-
f.write(sorted_records_as_jsonl)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def cleanup_files
|
47
|
-
[ @filename_sorted_jsonl, @filename_jsonl, @filename_sorted_csv, @filename_csv ].each do |p|
|
48
|
-
next if p.nil?
|
49
|
-
p.unlink if p.exist?
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def records
|
54
|
-
@records ||= Array.new.tap do |a|
|
55
|
-
count.times do
|
56
|
-
a << Hash.new.tap do |h|
|
57
|
-
fields.each do |f|
|
58
|
-
value = (f == 'slug') ? generate_slug : ::Faker::Device.send(f)
|
59
|
-
h[f] = value
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def sorted_records
|
67
|
-
@sorted_records ||= records.sort_by do |r|
|
68
|
-
compare_fields.map { |field| r[field] }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def records_as_jsonl
|
73
|
-
@jsonl_records ||= as_jsonl(list: records)
|
74
|
-
end
|
75
|
-
|
76
|
-
def records_as_csv
|
77
|
-
@csv_records ||= as_csv(list: records)
|
78
|
-
end
|
79
|
-
|
80
|
-
def records_as_csv_rows
|
81
|
-
@csv_rows ||= as_csv_rows(records_as_csv)
|
82
|
-
end
|
83
|
-
|
84
|
-
def sorted_records_as_jsonl
|
85
|
-
@jsonl_sorted_records ||= as_jsonl(list: sorted_records)
|
86
|
-
end
|
87
|
-
|
88
|
-
def sorted_records_as_csv
|
89
|
-
@csv_sorted_records ||= as_csv(list: sorted_records)
|
90
|
-
end
|
91
|
-
|
92
|
-
def sorted_records_as_csv_rows
|
93
|
-
@csv_sorted_rows ||= as_csv_rows(sorted_records_as_csv)
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def as_jsonl(list:)
|
99
|
-
list.map { |r| Oj.dump(r) }.join("\n") + "\n"
|
100
|
-
end
|
101
|
-
|
102
|
-
def as_csv(list:, headers: fields)
|
103
|
-
CSV.generate('', headers: headers , write_headers: true) do |csv|
|
104
|
-
list.each do |r|
|
105
|
-
csv << fields.map { |f| r[f] }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def as_csv_rows(text)
|
111
|
-
Array.new.tap do |a|
|
112
|
-
CSV.new(text, converters: :numeric, headers: :first_row, return_headers: false).each do |row|
|
113
|
-
a << row
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module TestFieldType
|
4
|
-
class TestBooleanType < ::Minitest::Test
|
5
|
-
def truthy_items
|
6
|
-
t = %w[ yes Y true t 1 y ]
|
7
|
-
t << 1
|
8
|
-
end
|
9
|
-
|
10
|
-
def falsey_items
|
11
|
-
f = %w[ no n false f 0 N ]
|
12
|
-
f << 0
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_true
|
16
|
-
assert(FlatKit::FieldType::BooleanType.matches?(true))
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_false
|
20
|
-
assert(FlatKit::FieldType::BooleanType.matches?(false))
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_truthy_items
|
24
|
-
truthy_items.each do |s|
|
25
|
-
assert(FlatKit::FieldType::BooleanType.matches?(s), "#{s} should be boolean")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_falsey_items
|
30
|
-
falsey_items.each do |s|
|
31
|
-
assert(FlatKit::FieldType::BooleanType.matches?(s), "#{s} should be boolean")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_other_class_does_not_match
|
36
|
-
refute(FlatKit::FieldType::BooleanType.matches?(Object.new))
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_coerces_falsey_to_boolean
|
40
|
-
falsey_items.each do |t|
|
41
|
-
refute(FlatKit::FieldType::BooleanType.coerce(t))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_true_is_truthy
|
46
|
-
assert(FlatKit::FieldType::BooleanType.coerce(true))
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_false_is_falsey
|
50
|
-
refute(FlatKit::FieldType::BooleanType.coerce(false))
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_0_is_false
|
54
|
-
refute(FlatKit::FieldType::BooleanType.coerce(0))
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_1_is_false
|
58
|
-
assert(FlatKit::FieldType::BooleanType.coerce(1))
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_42_is_false
|
62
|
-
assert(FlatKit::FieldType::BooleanType.coerce(42.0))
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module TestFieldType
|
4
|
-
class TestDateType < ::Minitest::Test
|
5
|
-
def test_time_does_not_match
|
6
|
-
refute(FlatKit::FieldType::DateType.matches?(Time.now))
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_date
|
10
|
-
assert(FlatKit::FieldType::DateType.matches?(Date.today))
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_datetime_does_not_match
|
14
|
-
refute(FlatKit::FieldType::DateType.matches?(DateTime.now))
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_formats
|
18
|
-
formats = ::FlatKit::FieldType::DateType.parse_formats
|
19
|
-
|
20
|
-
assert_equal(formats.size, formats.sort.uniq.size)
|
21
|
-
|
22
|
-
formats.each do |df|
|
23
|
-
s = Time.now.strftime("#{df}")
|
24
|
-
assert(FlatKit::FieldType::DateType.matches?(s), "#{s} should match date")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_other_class_does_not_match
|
29
|
-
[ 42, Object.new, true, false ].each do |x|
|
30
|
-
refute(FlatKit::FieldType::DateType.matches?(x), "#{x} should not be date")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_N_number_does_not_match
|
35
|
-
x = "N89362"
|
36
|
-
refute(FlatKit::FieldType::DateType.matches?(x), "#{x} should not be date")
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_coerce
|
40
|
-
formats = ::FlatKit::FieldType::DateType.parse_formats
|
41
|
-
|
42
|
-
formats.each do |df|
|
43
|
-
s = Time.now.strftime("#{df}")
|
44
|
-
assert_instance_of(Date, FlatKit::FieldType::DateType.coerce(s), "#{s} should convert to date")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_date_coerce_does_not_passthrough_time
|
49
|
-
t = Time.now
|
50
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, FlatKit::FieldType::DateType.coerce(t))
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_date_coerce_passthrough_date
|
54
|
-
t = Date.today
|
55
|
-
assert_equal(t, FlatKit::FieldType::DateType.coerce(t))
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_date_coerce_does_not_passthrough_datetime
|
59
|
-
t = DateTime.now
|
60
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, FlatKit::FieldType::DateType.coerce(t))
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_number_coerce_failure
|
64
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, FlatKit::FieldType::DateType.coerce(42))
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_number_coerce_failure_bad_parse
|
68
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, FlatKit::FieldType::DateType.coerce("1234 56 78 90"))
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module TestFieldType
|
4
|
-
class TestFloatType < ::Minitest::Test
|
5
|
-
def test_float_matches
|
6
|
-
assert(FlatKit::FieldType::FloatType.matches?(42.0))
|
7
|
-
assert(FlatKit::FieldType::FloatType.matches?(42.1))
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_integer_does_not_match
|
11
|
-
refute(FlatKit::FieldType::FloatType.matches?(42))
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_string_of_digits_does_not_match
|
15
|
-
refute(FlatKit::FieldType::FloatType.matches?("42"))
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_string_of_digits_with_dot_matches
|
19
|
-
assert(FlatKit::FieldType::FloatType.matches?("42.0"))
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_string_of_leters_does_not_match
|
23
|
-
refute(FlatKit::FieldType::FloatType.matches?("abc"))
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_scientific_notation_matches
|
27
|
-
assert(FlatKit::FieldType::FloatType.matches?("1e-10"))
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_other_class_does_not_match
|
31
|
-
refute(FlatKit::FieldType::FloatType.matches?(Object.new))
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_integer_coerces
|
35
|
-
assert_equal(42.0, ::FlatKit::FieldType::FloatType.coerce(42))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_integer_strings_coerce
|
39
|
-
assert_equal(42.0, ::FlatKit::FieldType::FloatType.coerce("42"))
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_float_strings_coerce
|
43
|
-
assert_equal(42.6, ::FlatKit::FieldType::FloatType.coerce("42.6"))
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_float_coerces
|
47
|
-
assert_equal(42.6, ::FlatKit::FieldType::FloatType.coerce(42.6))
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_non_numercic_do_not_coerce
|
51
|
-
[ "eleven", nil, false, Object.new ].each do |nope|
|
52
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, ::FlatKit::FieldType::FloatType.coerce(nope))
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module TestFieldType
|
4
|
-
class TestGuessType < ::Minitest::Test
|
5
|
-
|
6
|
-
def test_guess_type_should_not_match_anything
|
7
|
-
refute(FlatKit::FieldType::GuessType.matches?(nil))
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_guess_type_returns_coerce_failure
|
11
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, ::FlatKit::FieldType::GuessType.coerce(nil))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module TestFieldType
|
4
|
-
class TestIntegerType < ::Minitest::Test
|
5
|
-
def test_matches_integer
|
6
|
-
assert(FlatKit::FieldType::IntegerType.matches?(42))
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_matches_negative_integer
|
10
|
-
assert(FlatKit::FieldType::IntegerType.matches?("-42"))
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_float_does_not_match
|
14
|
-
refute(FlatKit::FieldType::IntegerType.matches?(42.0))
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_string_of_digits_matches
|
18
|
-
assert(FlatKit::FieldType::IntegerType.matches?("42"))
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_string_with_some_digiets_does_not_match
|
22
|
-
refute(FlatKit::FieldType::IntegerType.matches?("42.0"))
|
23
|
-
refute(FlatKit::FieldType::IntegerType.matches?("abc"))
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_other_class_does_not_match
|
27
|
-
refute(FlatKit::FieldType::IntegerType.matches?(Object.new))
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_integer_coerces
|
31
|
-
assert_equal(42, ::FlatKit::FieldType::IntegerType.coerce(42))
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_integer_strings_coerce
|
35
|
-
assert_equal(42, ::FlatKit::FieldType::IntegerType.coerce("42"))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_float_coerces
|
39
|
-
assert_equal(42, ::FlatKit::FieldType::IntegerType.coerce(42.6))
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_float_strings_do_not_coerce
|
43
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, ::FlatKit::FieldType::IntegerType.coerce("42.6"))
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_non_numercic_do_not_coerce
|
47
|
-
[ "eleven", nil, false, Object.new ].each do |nope|
|
48
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, ::FlatKit::FieldType::IntegerType.coerce(nope))
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module TestFieldType
|
4
|
-
class TestNullType < ::Minitest::Test
|
5
|
-
def nully_items
|
6
|
-
[ "null", "NULL", "nil", "\\N" ]
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_null
|
10
|
-
assert(FlatKit::FieldType::NullType.matches?(nil))
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_nully_items
|
14
|
-
nully_items.each do |s|
|
15
|
-
assert(FlatKit::FieldType::NullType.matches?(s), "#{s} should be null")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_other_class_does_not_match
|
20
|
-
[ 42, Object.new, true, false ].each do |x|
|
21
|
-
refute(FlatKit::FieldType::NullType.matches?(x), "#{x} should not be == null")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_coerce_coerces_nil
|
26
|
-
assert_nil(FlatKit::FieldType::NullType.coerce(nil))
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_coerces_nully_items
|
30
|
-
nully_items.each do |s|
|
31
|
-
assert_nil(FlatKit::FieldType::NullType.coerce(s))
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_coerce_failure_non_non_nully_items
|
36
|
-
[ "whatever", 42, Object.new, true, false, Class].each do |x|
|
37
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, FlatKit::FieldType::NullType.coerce(x))
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
module TestFieldType
|
4
|
-
class TestStringType < ::Minitest::Test
|
5
|
-
|
6
|
-
def test_string_will_not_match_non_string_data
|
7
|
-
[42, false, true, 12.5, Object.new].each do |o|
|
8
|
-
refute(FlatKit::FieldType::StringType.matches?(o))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_string_type_returns_coerce_failures
|
13
|
-
[BasicObject.new].each do |o|
|
14
|
-
assert_equal(::FlatKit::FieldType::CoerceFailure, ::FlatKit::FieldType::StringType.coerce(o))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|