cvg 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2U0OTc4YjRkMDc1NzBlZGM1OGM3MTU1OTVkYmMyMGEwN2I1ZWM4OQ==
4
+ NGYyMzdiYzVmMjM0MDI5Y2MzMGNjN2QwNjdkNWM0ZDdlOGZhZDM1OA==
5
5
  data.tar.gz: !binary |-
6
- OGM3NmFmZmM0YmExY2MyZjI3MmNmMTBkNjljYzU3MWI5ZTc5NDdkOA==
6
+ N2IyN2E4ZDM5MDZiYzQwOTBiMmViNWJiMmM2YWIyZDMxMWNkNDQ4Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzZjYzUyMmM3ZWEyNDRiYThkOTk3M2YyOTFiNGI5OTJlOGQ0YWRhNjdhYzBk
10
- NWIxNThhZmJiN2YzYTE0OTgzNjhiODc3MTk0NmJkZDhmOWU4ZTBmM2MzYzU2
11
- ZDJhZmEzYmVmZDZhZDY4MTAyNGE3MjFhZWUxNGIzYjQxOWNiMGI=
9
+ NGEyMjk2ODM0MmNjNjQ1NjllM2RiZWFhN2FlZDdlZTA5N2RmNzNlMjIyNWI1
10
+ ZWJhYjIxYzk5NGVjNWVmZGQ3NjlmNTc1Y2NlYmRlY2QxY2NmYWU5MzMzZTRm
11
+ Y2Q3MjJmYWZiYzVjZWU5MTgyMWMyNmE4MGYzMDY5Zjk0Yjg4ZTE=
12
12
  data.tar.gz: !binary |-
13
- Zjk0NTRmNTI5YTA1MTFlMGZkZTY3OTVlY2FjYjU3OWQzZTQzNGM3Mjg3YWMy
14
- NmVkNGQzMjM2OTA2ZDc3MWVmODBkYTBiZGQyZTU5MTZiMjg0MTIzNjhmNWE2
15
- ZDJjYjM0ZmU3YWVkZGUyOTAzMWQ2N2JlNjNlMTYxNWNiY2JlOTg=
13
+ MTliZjBlY2ZlM2JlZThhM2Y5YWFmYzk0NWEyNTc0MmNiOGYxMmYzYjk4OWIy
14
+ ODZmMmM4OGNhMTQxZWIzMzdlYzEyODJkMTFmMTU3MGFmYmE3Yzc1N2JlMTFk
15
+ ZTRjYWUxZjI5MzQ0ZmZmMWIxMjk2NjVkOGNiNTI0MDdmMWNlNDg=
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.1.0 / 2013-11-08
2
+
3
+ * Breaking changes
4
+
5
+ * --value and --regex have been combined and replaced with --match
6
+
1
7
  0.0.2 / 2013-11-05
2
8
 
3
9
  * Enhancements
data/README.md CHANGED
@@ -6,7 +6,9 @@ cvg --present colA input.csv
6
6
 
7
7
  cvg --missing colA input.csv
8
8
 
9
- cvg --regex 'colA:/\d+/' input.csv
9
+ cvg --match 'colA:/\d+/' input.csv
10
+
11
+ cvg --match 'colA:one,two,three,/\d+/' input.csv
10
12
 
11
13
  cvg --detect-missing input.csv
12
14
 
@@ -42,6 +44,8 @@ DONE treat as missing %w{ N/A n/a NULL null - #DIV/0 #REF! #NAME? NIL nil NA na
42
44
 
43
45
  writes report (why rejected row, checks missing and extra columns across input files)
44
46
 
45
- dup checks on certain cols
47
+ DONE dup checks on certain cols
46
48
 
47
49
  optionall uses minimal set of headers shared by all
50
+
51
+ make it possible to match a field that starts with a /
data/bin/cvg CHANGED
@@ -68,32 +68,33 @@ class Cvg
68
68
  end
69
69
  end
70
70
 
71
- class Regex < Test
71
+ class Match < Test
72
72
  class << self
73
73
  def accept(k, arg)
74
- new(k, arg) if k == 'regex'
75
- end
76
- end
77
- def pass?(row)
78
- !!(row.fetch(col).to_s =~ regex)
79
- end
80
- def regex
81
- @regex ||= arg.split(':', 2)[1].to_regexp(detect: true) or raise("#{arg.inspect} doesn't have a valid regex")
82
- end
83
- end
84
-
85
- class Value < Test
86
- class << self
87
- def accept(k, arg)
88
- new(k, arg) if k == 'value'
74
+ new(k, arg) if k == 'match'
89
75
  end
90
76
  end
77
+ REGEX_START_1 = '/'
78
+ REGEX_START_2 = '%r{'
91
79
  def pass?(row)
92
80
  v = row.fetch(col).to_s
93
- values.include? v
81
+ matchers.any? do |matcher|
82
+ case matcher
83
+ when ::Regexp
84
+ matcher =~ v
85
+ else
86
+ matcher == v
87
+ end
88
+ end
94
89
  end
95
- def values
96
- @values ||= CSV.parse_line arg.split(':', 2)[1]
90
+ def matchers
91
+ @matchers ||= CSV.parse_line(arg.split(':', 2)[1]).map do |x|
92
+ if x.start_with?(REGEX_START_1) or x.start_with?(REGEX_START_2)
93
+ x.to_regexp or die("invalid regex #{x.inspect}")
94
+ else
95
+ x
96
+ end
97
+ end
97
98
  end
98
99
  end
99
100
 
@@ -165,7 +166,7 @@ class Cvg
165
166
  end
166
167
  end
167
168
 
168
- TESTS = [Present, Missing, Regex, Value, GreaterOrLesser, Dedup]
169
+ TESTS = [Present, Missing, Match, GreaterOrLesser, Dedup]
169
170
  FLAGS = {
170
171
  'detect-missing' => DetectMissing,
171
172
  }
@@ -45,7 +45,7 @@ Feature: Basic functionality
45
45
  yes,a1
46
46
  yes,1a
47
47
  """
48
- When you pass arguments --regex 'b:/\d+/'
48
+ When you pass arguments --match 'b:/\d+/'
49
49
  Then you get output
50
50
  """
51
51
  a,b
@@ -65,7 +65,7 @@ Feature: Basic functionality
65
65
  no,zz
66
66
  no,ZZ
67
67
  """
68
- When you pass arguments --value 'b:z'
68
+ When you pass arguments --match 'b:z'
69
69
  Then you get output
70
70
  """
71
71
  a,b
@@ -83,7 +83,7 @@ Feature: Basic functionality
83
83
  no,ZZ
84
84
  yes,Z
85
85
  """
86
- When you pass arguments --value 'b:z,Z'
86
+ When you pass arguments --match 'b:z,Z'
87
87
  Then you get output
88
88
  """
89
89
  a,b
@@ -91,6 +91,24 @@ Feature: Basic functionality
91
91
  yes,Z
92
92
  """
93
93
 
94
+ Scenario: Mixed regex and literals
95
+ Given an input csv
96
+ """
97
+ a,b
98
+ yes,z
99
+ yes,a
100
+ yes,Z
101
+ no,
102
+ """
103
+ When you pass arguments --match 'b:a,/Z/i'
104
+ Then you get output
105
+ """
106
+ a,b
107
+ yes,z
108
+ yes,a
109
+ yes,Z
110
+ """
111
+
94
112
  Scenario: Less than
95
113
  Given an input csv
96
114
  """
@@ -1,3 +1,3 @@
1
1
  module Cvg
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cvg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport