xlgrep 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfeb38151e8a2c8b11cd8017c2d8e37f1426c1c1
4
- data.tar.gz: b4946644f38765a04f90324579a0462edbc5c2c7
3
+ metadata.gz: da79ac328f63cdd9700cf2dd26b300c7f91016e4
4
+ data.tar.gz: 8aa823fe2d96c12df0bb3ba1d19f2bed366835a2
5
5
  SHA512:
6
- metadata.gz: 05c6ff8ece6dab044c8ce937de0409b7ba63e47a9ab0a91e16aa4a3fd2ea0649fd0122fe4d4ed829933b4bd91acee1b88813d4cb93396139ee42dc207e3ba609
7
- data.tar.gz: c200dd85818e5571a868d30c17f7354f0a585dbbe6b22d3b73d8abd8e44ab17880449fb89cf789e6a3e886047911c480987dbdfc26d7e101f1211563fb35e30a
6
+ metadata.gz: be59a3bb9517df737cd87445db72e20e8d34a8146c8470d383b528629ae603025ac85afa29e8c09751b922afef186a11b82deadf267ab9088f3ad4a4ea705118
7
+ data.tar.gz: 9b4c10783560c7f146fd1fa7f90b301b9b9625c3899703151e68ff4ab606108d67312f01ca3c5a9c7b1b7fb95887cb1ff4e1830c188786f06157919cab8d21a1
data/bin/xlgrep CHANGED
@@ -2,4 +2,42 @@
2
2
 
3
3
  require 'xlgrep'
4
4
 
5
- Xlgrep.invalid_json(ARGV)
5
+ require 'trollop'
6
+ opts = Trollop::options do
7
+ version "xlgrep-#{Xlgrep::VERSION}"
8
+
9
+ banner <<-EOS
10
+ xlgrep scans your spreadsheet files for EXCEL, OpenOffice, Google spreadsheets, Excelx, LibreOffice and CSV
11
+
12
+ Usage:
13
+ xlgrep <keyword> <filenames>+
14
+ OR xlgrep [options] <filenames>+
15
+
16
+ where [options] are:
17
+ EOS
18
+
19
+ opt :regexp, "use ruby Regexp", type: :string
20
+ opt :json , "use json validator"
21
+ end
22
+
23
+ predicates = []
24
+ opts.each do |key, val|
25
+ pred =
26
+ case key
27
+ when :json then Xlgrep::InvalidJson if val
28
+ when :regexp then Xlgrep::Regexp.new(val) if val
29
+ end
30
+ next unless pred
31
+ predicates << pred
32
+ end
33
+
34
+ if predicates.empty?
35
+ if ARGV.first && !File.exist?(ARGV.first)
36
+ predicates << Xlgrep::Regexp.new(ARGV.shift)
37
+ else
38
+ puts "no option given, see `xlgrep --help`"
39
+ exit(1)
40
+ end
41
+ end
42
+
43
+ Xlgrep.run(predicates, ARGV)
@@ -3,7 +3,11 @@ require "xlgrep/version"
3
3
  module Xlgrep
4
4
 
5
5
  autoload :Context , "xlgrep/context"
6
+
6
7
  autoload :InvalidJson, "xlgrep/invalid_json"
8
+ autoload :Regexp , "xlgrep/regexp"
9
+
10
+ autoload :ResultBuffer , "xlgrep/result_buffer"
7
11
  autoload :SimpleFormatter, "xlgrep/simple_formatter"
8
12
 
9
13
  class << self
@@ -16,8 +20,8 @@ module Xlgrep
16
20
  end
17
21
  end
18
22
 
19
- def run(predicates, files)
20
- Context.new(predicates).execute(files)
23
+ def run(predicates, files, formatter = nil)
24
+ Context.new(predicates, formatter).execute(files)
21
25
  end
22
26
  end
23
27
 
@@ -12,6 +12,13 @@ module Xlgrep
12
12
 
13
13
  def book_for(file)
14
14
  Roo::Spreadsheet.open(file)
15
+ rescue => e
16
+ if e.is_a?(NoMethodError) && (e.message =~ /for nil:NilClass/)
17
+ $stderr.puts("SKIP #{file} unsupported file")
18
+ else
19
+ $stderr.puts("SKIP #{file} [#{e.class}] #{e.message}")
20
+ end
21
+ return nil
15
22
  end
16
23
 
17
24
  BASE_CHAR_ORDER = 'A'.ord
@@ -19,6 +26,7 @@ module Xlgrep
19
26
  def execute(files)
20
27
  files.each do |f|
21
28
  book = book_for(f)
29
+ next unless book
22
30
  book.sheets.each do |sheet|
23
31
  print_status("loading #{f} #{sheet}")
24
32
 
@@ -0,0 +1,17 @@
1
+ require 'xlgrep'
2
+
3
+ require 'json'
4
+
5
+ module Xlgrep
6
+ class Regexp
7
+ def initialize(expression)
8
+ @impl = /#{expression}/
9
+ end
10
+
11
+ def match(str)
12
+ if str =~ @impl
13
+ yield("MATCH")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'xlgrep'
2
+
3
+ module Xlgrep
4
+ class ResultBuffer
5
+
6
+ attr_reader :result
7
+ def initialize
8
+ @result = []
9
+ end
10
+
11
+ def process(obj)
12
+ @result << obj
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Xlgrep
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Xlgrep do
@@ -5,10 +6,12 @@ describe Xlgrep do
5
6
  Xlgrep::VERSION.should_not be_nil
6
7
  end
7
8
 
8
- it 'should do something useful' do
9
+ let(:buffer){ Xlgrep::ResultBuffer.new }
10
+
11
+ it '.invalid_json' do
9
12
  Dir.chdir(File.expand_path("..", __FILE__)) do
10
- r = Xlgrep.invalid_json(Dir.glob("examples/**/*.*"))
11
- r.should == [
13
+ Xlgrep.run([Xlgrep::InvalidJson], Dir.glob("examples/**/*.*"), buffer)
14
+ buffer.result.should == [
12
15
  {file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 2, data: "{'foo': 1}" , msg: "757: unexpected token at '{'foo': 1}'"},
13
16
  {file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 3, data: "{\"foo\": 1, }" , msg: "757: unexpected token at '{\"foo\": 1, }'"},
14
17
  {file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 4, data: "{\"foo\", 1}" , msg: "757: unexpected token at '{\"foo\", 1}'"},
@@ -26,4 +29,19 @@ describe Xlgrep do
26
29
  ]
27
30
  end
28
31
  end
32
+
33
+ it '.regexp' do
34
+ Dir.chdir(File.expand_path("..", __FILE__)) do
35
+ Xlgrep.run([Xlgrep::Regexp.new("[A-Z]")], Dir.glob("examples/**/*.*"), buffer)
36
+ buffer.result.should == [
37
+ {:file=>"examples/json_example.xlsx", :sheet=>"invalid Object", :x=>"A", :y=>1, :msg=>"MATCH", :data=>"OK"},
38
+ {:file=>"examples/json_example.xlsx", :sheet=>"invalid Object", :x=>"B", :y=>1, :msg=>"MATCH", :data=>"NG"},
39
+ {:file=>"examples/json_example.xlsx", :sheet=>"invalid Object", :x=>"C", :y=>2, :msg=>"MATCH", :data=>"JSONでは文字列のリテラルとしてシングルクォーテーションは使えません"},
40
+ {:file=>"examples/json_example.xlsx", :sheet=>"invalid Array" , :x=>"A", :y=>1, :msg=>"MATCH", :data=>"OK"},
41
+ {:file=>"examples/json_example.xlsx", :sheet=>"invalid Array" , :x=>"B", :y=>1, :msg=>"MATCH", :data=>"NG"},
42
+ {:file=>"examples/json_example.xlsx", :sheet=>"invalid Array" , :x=>"C", :y=>2, :msg=>"MATCH", :data=>"JSONでは文字列のリテラルとしてシングルクォーテーションは使えません"},
43
+ ]
44
+ end
45
+ end
46
+
29
47
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency "roo", "~> 1.12.2"
22
22
  spec.add_runtime_dependency "highline"
23
+ spec.add_runtime_dependency "trollop"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlgrep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: trollop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +113,8 @@ files:
99
113
  - lib/xlgrep.rb
100
114
  - lib/xlgrep/context.rb
101
115
  - lib/xlgrep/invalid_json.rb
116
+ - lib/xlgrep/regexp.rb
117
+ - lib/xlgrep/result_buffer.rb
102
118
  - lib/xlgrep/simple_formatter.rb
103
119
  - lib/xlgrep/version.rb
104
120
  - spec/examples/json_example.xlsx