syc-spector 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Welcome to syc-spector
1
+ == Welcome to syc-spector
2
2
  home :: https://github.com/sugaryourcoffee/syc-spector
3
3
 
4
4
  == Description
@@ -6,10 +6,10 @@ The sycspector scans a file for patterns provided on the command line.
6
6
  Lines that match the pattern are saved to a file with valid values and those lines that don't match the pattern are added to a file with invalid values.
7
7
  The valid and invalid files as well as the used pattern are stored in a
8
8
  history file. The saved values are used for a subsequent call to sycspector
9
- with --show and -f for fix to show the results or to prompt the invalid values to fix them. Fixed values can appended to the valid values file.
9
+ with --show and -f for fix to show the results or to prompt the invalid values to fix them. Fixed values can be appended to the valid values file.
10
10
 
11
11
  == Installation
12
- sycspector can be installed as a gem from [RubyGems](http://RubyGems.org) with
12
+ sycspector can be installed as a gem from http://RubyGems.org with
13
13
  $ gem install syc-spector
14
14
 
15
15
  == Invokation Examples
@@ -51,4 +51,4 @@ To process all at once
51
51
  $ sycspector -fis inputfile -o outputfile -p "\A\w+, w+\Z" --show
52
52
 
53
53
  == License
54
- syc-spector is released under the {MIT License}[http://www.opensource.org/license/MIT].
54
+ syc-spector is released under the {MIT License}[http://www.opensource.org/licenses/MIT].
@@ -98,9 +98,6 @@ module Inspector
98
98
 
99
99
  # Create a flag
100
100
 
101
- @options[:pattern] = /\A.*\Z/
102
- @options[:scan_pattern] = /\A.*\Z/
103
-
104
101
  opts.on("-p", "--pattern PATTERN",
105
102
  "Values that match the pattern are",
106
103
  "considered as valid values.",
@@ -165,8 +162,10 @@ module Inspector
165
162
  File.open(".sycspector.data", 'r') do |file|
166
163
  files = create_output_files file.gets.chomp
167
164
  argv << file.gets.chomp
168
- @options[:pattern] = Regexp.new(file.gets.chomp)
169
- @options[:scan_pattern] = Regexp.new(file.gets.chomp)
165
+ unless @options[:pattern]
166
+ @options[:pattern] = Regexp.new(file.gets.chomp)
167
+ @options[:scan_pattern] = Regexp.new(file.gets.chomp)
168
+ end
170
169
  end
171
170
  else
172
171
  STDERR.puts "--> no sycspector history.\n" +
@@ -205,6 +204,11 @@ module Inspector
205
204
  @options[:valid_file] = files[:valid_file]
206
205
  @options[:invalid_file] = files[:invalid_file]
207
206
  end
207
+
208
+ unless @options[:pattern]
209
+ @options[:pattern] = DEFAULT_PATTERN
210
+ @options[:scan_pattern] = DEFAULT_PATTERN
211
+ end
208
212
  end
209
213
  end
210
214
  end
@@ -6,6 +6,9 @@ EMAIL_PATTERN = /\A[\w!#\$%&'*+\/=?`{|}~^-]+(?:\.[\w!#\$%&'*+\/=?`{|}~^-]+)*@(?:
6
6
  # Pattern that relizes an email within a line.
7
7
  ANY_EMAIL_PATTERN = /[\w!#\$%&'*+\/=?`{|}~^-]+(?:\.[\w!#\$%&'*+\/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}/
8
8
 
9
+ # Default pattern scanning whole lines
10
+ DEFAULT_PATTERN = /\A.*\Z/
11
+
9
12
  # Pattern that relizes strings between \A and \Z that is beginning of line and
10
13
  # end of line patterns.
11
14
  FULL_LINE = /(?<=\\A).*(?=\\Z)/
@@ -136,7 +136,7 @@ module Inspector
136
136
  invalid_values << value
137
137
  end
138
138
  else
139
- valid_values << match
139
+ valid_values << match.to_s
140
140
  end
141
141
  end
142
142
  end
@@ -145,7 +145,7 @@ module Inspector
145
145
  valid_counter = valid_values.size
146
146
 
147
147
  valid_values.uniq! {|value| value.downcase } if opts[:individualize]
148
- valid_values.sort! if opts[:sort]
148
+ valid_values.sort! {|a,b| a.downcase <=> b.downcase } if opts[:sort]
149
149
 
150
150
  valid_values.each do |value|
151
151
  valid_file.puts value
Binary file
data/sycspector.gemspec CHANGED
@@ -1,11 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "syc-spector"
3
- s.summary =
4
- "Analyze a file and extract values matching a provided pattern.\n \
5
- Allow to sort, remove double and manually fix values."
6
- s.description = File.read(File.join(File.dirname(__FILE__), 'README'))
3
+ s.summary = "Extract, sort and individualize values from a file"
4
+ s.description = File.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
7
5
  s.requirements = ['No requirements']
8
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
9
7
  s.author = "Pierre Sugar"
10
8
  s.email = "pierre@sugaryourcoffee.de"
11
9
  s.homepage = "http://syc.dyndns.org/drupal"
@@ -15,4 +13,5 @@ Gem::Specification.new do |s|
15
13
  s.executables = ['sycspector']
16
14
  s.test_files = Dir['test/test*.rb']
17
15
  s.has_rdoc = true
16
+ s.extra_rdoc_files = ['README.rdoc']
18
17
  end
data/test/test_options.rb CHANGED
@@ -30,7 +30,6 @@ class TestOptions < Test::Unit::TestCase
30
30
 
31
31
  # Intializes the input, valid, invalid and history file
32
32
  def setup
33
- puts "in startup"
34
33
  File.open('existing', 'w') do |file|
35
34
  file.puts "pierre@thesugars.de"
36
35
  file.puts "amanda@thesugars.de und pierre@thesugars.de"
@@ -38,11 +37,11 @@ class TestOptions < Test::Unit::TestCase
38
37
  File.open('.sycspector.data', 'w') do |file|
39
38
  file.puts "20130113-121212_valid_values"
40
39
  file.puts "20130113-121212_invalid_values"
41
- file.puts "(?-mix:\A[\w!#\$%&'*+\/=?`{|}~^-]+" +
42
- "(?:\.[\w!#\$%&'*+\/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\.)+" +
43
- "[a-zA-Z]{2,6}\Z)"
44
- file.puts "(?-mix:[\w!#\$%&'*+\/=?`{|}~^-]+" +
45
- "(?:\.[\w!#\$%&'*+\/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\.)+" +
40
+ file.puts "(?-mix:\\A[\\w!#\\$%&'*+\/=?`{|}~^-]+" +
41
+ "(?:\\.[\\w!#\\$%&'*+\/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+" +
42
+ "[a-zA-Z]{2,6}\\Z)"
43
+ file.puts "(?-mix:[\\w!#\\$%&'*+\/=?`{|}~^-]+" +
44
+ "(?:\\.[\\w!#\\$%&'*+\/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+" +
46
45
  "[a-zA-Z]{2,6})"
47
46
  end
48
47
  File.open('20130113-121212_valid_values', 'w') do |file|
@@ -57,15 +56,16 @@ class TestOptions < Test::Unit::TestCase
57
56
 
58
57
  # Cleans up the test directory by deleting the files created in setup
59
58
  def teardown
60
- puts "in shutdown"
61
59
  `rm existing`
62
60
  `rm 20130113-*`
63
61
  `rm .sycspector.data`
64
62
  end
65
63
 
66
- should "return inputfile" do
64
+ should "return inputfile and default pattern" do
67
65
  opts = Inspector::Options.new(["existing"])
68
66
  assert_equal "existing", opts.options[:infile]
67
+ assert_equal DEFAULT_PATTERN, opts.options[:pattern]
68
+ assert_equal DEFAULT_PATTERN, opts.options[:scan_pattern]
69
69
  end
70
70
 
71
71
  should "return email pattern" do
@@ -104,12 +104,29 @@ class TestOptions < Test::Unit::TestCase
104
104
  assert_equal nil, opts.options[:infile]
105
105
  end
106
106
 
107
- should "return fix and invalid file as input file from last invokation" do
107
+ should "return fix and invalid file as input file and pattern "+
108
+ "from last invokation" do
108
109
  opts = Inspector::Options.new(["-f"])
109
110
  assert_equal true, opts.options[:fix]
110
111
  assert_equal "20130113-121212_invalid_values", opts.options[:infile]
112
+
113
+ pattern_match =
114
+ "a@b.c".match(EMAIL_PATTERN).to_s ==
115
+ "a@b.c".match(opts.options[:pattern]).to_s
116
+ scan_pattern_match =
117
+ "is a@b.c here?".match(ANY_EMAIL_PATTERN).to_s ==
118
+ "is a@b.c here?".match(opts.options[:scan_pattern]).to_s
119
+
120
+ assert_equal true, pattern_match
121
+ assert_equal true, scan_pattern_match
111
122
  end
112
123
 
124
+ should "return fix and provided pattern and scan_pattern" do
125
+ opts = Inspector::Options.new(["-f", "-p", "\\A\\w+@\\w+\\.\\w+\\Z"])
126
+ assert_equal true, opts.options[:fix]
127
+ assert_equal /\A\w+@\w+\.\w+\Z/, opts.options[:pattern]
128
+ assert_equal /\w+@\w+\.\w+/, opts.options[:scan_pattern]
129
+ end
113
130
  end
114
131
 
115
132
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syc-spector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,18 +9,18 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-16 00:00:00.000000000 Z
12
+ date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ! "= Welcome to syc-spector\n home :: https://github.com/sugaryourcoffee/syc-spector\n\n==
14
+ description: ! "== Welcome to syc-spector\n home :: https://github.com/sugaryourcoffee/syc-spector\n\n==
15
15
  Description\nThe sycspector scans a file for patterns provided on the command line.\nLines
16
16
  that match the pattern are saved to a file with valid values and those lines that
17
17
  don't match the pattern are added to a file with invalid values.\nThe valid and
18
18
  invalid files as well as the used pattern are stored in a\nhistory file. The saved
19
19
  values are used for a subsequent call to sycspector\nwith --show and -f for fix
20
20
  to show the results or to prompt the invalid values to fix them. Fixed values can
21
- appended to the valid values file.\n\n== Installation\nsycspector can be installed
22
- as a gem from [RubyGems](http://RubyGems.org) with\n $ gem install syc-spector\n\n==
23
- Invokation Examples\nRearches for email addresses in the provided file 'email_addresses'\n
21
+ be appended to the valid values file.\n\n== Installation\nsycspector can be installed
22
+ as a gem from http://RubyGems.org with\n $ gem install syc-spector\n\n== Invokation
23
+ Examples\nRearches for email addresses in the provided file 'email_addresses'\n
24
24
  \ $ sycspector email_addresses -p email\n\nLines that are not recognized can be
25
25
  prompted, fixed and appended to the\nvalid file with\n $ sycspector -fa\n\nTo show
26
26
  the result of the invokation use\n $ sycspector --show\n\nTo fix the values from
@@ -36,12 +36,13 @@ description: ! "= Welcome to syc-spector\n home :: https://github.com/sugaryourc
36
36
  the file where the results (valid and invalid) should go to\n $ sycspector -fa
37
37
  -o outputfile\n\nTo process all at once\n $ sycspector -fis inputfile -o outputfile
38
38
  -p \"\\A\\w+, w+\\Z\" --show\n\n== License\nsyc-spector is released under the {MIT
39
- License}[http://www.opensource.org/license/MIT].\n"
39
+ License}[http://www.opensource.org/licenses/MIT].\n"
40
40
  email: pierre@sugaryourcoffee.de
41
41
  executables:
42
42
  - sycspector
43
43
  extensions: []
44
- extra_rdoc_files: []
44
+ extra_rdoc_files:
45
+ - README.rdoc
45
46
  files:
46
47
  - syc-spector-0.0.1.gem
47
48
  - README.rdoc
@@ -97,9 +98,10 @@ files:
97
98
  - doc/Inspector/Options.html
98
99
  - doc/Inspector/Runner.html
99
100
  - doc/TestConsole.html
101
+ - syc-spector-0.0.3.gem
100
102
  - sycspector.gemspec
101
103
  - bin/sycspector
102
- - README
104
+ - syc-spector-0.0.2.gem
103
105
  homepage: http://syc.dyndns.org/drupal
104
106
  licenses: []
105
107
  post_install_message:
@@ -124,8 +126,7 @@ rubyforge_project:
124
126
  rubygems_version: 1.8.24
125
127
  signing_key:
126
128
  specification_version: 3
127
- summary: Analyze a file and extract values matching a provided pattern. Allow to sort,
128
- remove double and manually fix values.
129
+ summary: Extract, sort and individualize values from a file
129
130
  test_files:
130
131
  - test/test_options.rb
131
132
  - test/test_separator.rb
data/README DELETED
@@ -1,54 +0,0 @@
1
- = Welcome to syc-spector
2
- home :: https://github.com/sugaryourcoffee/syc-spector
3
-
4
- == Description
5
- The sycspector scans a file for patterns provided on the command line.
6
- Lines that match the pattern are saved to a file with valid values and those lines that don't match the pattern are added to a file with invalid values.
7
- The valid and invalid files as well as the used pattern are stored in a
8
- history file. The saved values are used for a subsequent call to sycspector
9
- with --show and -f for fix to show the results or to prompt the invalid values to fix them. Fixed values can appended to the valid values file.
10
-
11
- == Installation
12
- sycspector can be installed as a gem from [RubyGems](http://RubyGems.org) with
13
- $ gem install syc-spector
14
-
15
- == Invokation Examples
16
- Rearches for email addresses in the provided file 'email_addresses'
17
- $ sycspector email_addresses -p email
18
-
19
- Lines that are not recognized can be prompted, fixed and appended to the
20
- valid file with
21
- $ sycspector -fa
22
-
23
- To show the result of the invokation use
24
- $ sycspector --show
25
-
26
- To fix the values from the input file at the first scan
27
- $ sycspector -f email-addresses -p email
28
-
29
- To sort the values
30
- $ sycspector -s email-addresses -p email
31
-
32
- To fix, sort and remove duplicates (individualize)
33
- $ sycspector -fsi email-addresses -p email
34
-
35
- Matching patterns like 'name, firstname'
36
- $ syscpector name -p "\w+, \w+"
37
-
38
- Scanning only whole lines use
39
- $ sycspector name -p "\A\w+, \w+\A"
40
-
41
- If the file contains lines like "Doe, John and Doe, Jane" these won't be saved at the first scan but can be scanned with the --fix switch and appended to the valid values from the last run
42
- $ sycspector -fa
43
-
44
- Fixing a specific file by specifying the invalid file as inputfile
45
- $ sycspector -fa 2013016-083346_invalid_name -o 2013016-083346_valid_name
46
-
47
- Specifying the file where the results (valid and invalid) should go to
48
- $ sycspector -fa -o outputfile
49
-
50
- To process all at once
51
- $ sycspector -fis inputfile -o outputfile -p "\A\w+, w+\Z" --show
52
-
53
- == License
54
- syc-spector is released under the {MIT License}[http://www.opensource.org/license/MIT].