xlgrep 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/bin/xlgrep +17 -0
- data/lib/xlgrep/context.rb +53 -0
- data/lib/xlgrep/invalid_json.rb +19 -0
- data/lib/xlgrep/version.rb +3 -0
- data/lib/xlgrep.rb +25 -0
- data/spec/examples/json_example.xlsx +0 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/xlgrep_spec.rb +21 -0
- data/xlgrep.gemspec +26 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e6060ee213d9a665483b7c972cc354bd767aafa
|
4
|
+
data.tar.gz: 46fcc424bacc87d6c5212fd566eaef58cd4de850
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbc8007b40526c59cce749835711a8f9b6c6bf7c553990f6027d6a88b348c4889966c949156a9ac6892963d8df7d1576790e15ee953d4e63fcc3361e5f314676
|
7
|
+
data.tar.gz: 4a7a1f85ba8fe49c35b6b17c8dd66a8b4b3ba6134d471e1b7b750d31ed173ef0e5f50a157aa6b4b1eadde6704db50df5d1bd53e0250c1a6ded8fc9633ade47b9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 akima
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Xlgrep
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'xlgrep'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install xlgrep
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/xlgrep
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'xlgrep'
|
4
|
+
|
5
|
+
r = Xlgrep.invalid_json(ARGV)
|
6
|
+
|
7
|
+
require 'shellwords'
|
8
|
+
include Shellwords
|
9
|
+
|
10
|
+
r.each do |obj|
|
11
|
+
puts "-" * 80
|
12
|
+
puts "file : " << obj[:file]
|
13
|
+
puts "sheet : " << obj[:sheet]
|
14
|
+
puts "position: " << obj[:x] << obj[:y].to_s
|
15
|
+
puts "cell : " << obj[:data]
|
16
|
+
puts "msg : " << obj[:msg]
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'roo'
|
2
|
+
|
3
|
+
module Xlgrep
|
4
|
+
class Context
|
5
|
+
def initialize(predicates)
|
6
|
+
@predicates = predicates
|
7
|
+
end
|
8
|
+
|
9
|
+
def book_for(file)
|
10
|
+
klass, options =
|
11
|
+
case ext = File.extname(file)
|
12
|
+
when ".ods" then Roo::OpenOffice
|
13
|
+
when ".xls" then Roo::Excel
|
14
|
+
when ".xlsx" then Roo::Excelx
|
15
|
+
when ".csv" then Roo::CSV
|
16
|
+
when ".tsv" then [Roo::CSV, {csv_options: {col_sep: "\t"}}]
|
17
|
+
else raise ArgumentError, "Unsupported file extension: #{ext.inspect}"
|
18
|
+
end
|
19
|
+
klass.new(file, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
BASE_CHAR_ORDER = 'A'.ord
|
23
|
+
|
24
|
+
def execute(files)
|
25
|
+
result = []
|
26
|
+
files.each do |f|
|
27
|
+
book = book_for(f)
|
28
|
+
book.sheets.each do |sheet|
|
29
|
+
book.default_sheet = sheet
|
30
|
+
(book.first_row..book.last_row).each do |r|
|
31
|
+
cells = book.row(r)
|
32
|
+
cells.each.with_index do |cell, idx|
|
33
|
+
@predicates.each do |pred|
|
34
|
+
pred.match(cell) do |msg|
|
35
|
+
a, b = idx.divmod(26) # ('A'..'Z').length => 26
|
36
|
+
x = (a > 0 ? (BASE_CHAR_ORDER + a).chr : "") + (BASE_CHAR_ORDER + b).chr
|
37
|
+
result << {
|
38
|
+
file: f, sheet: sheet,
|
39
|
+
x: x, y: r,
|
40
|
+
data: cell,
|
41
|
+
msg: msg
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Xlgrep
|
4
|
+
module InvalidJson
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def match(str)
|
8
|
+
if str =~ /\A\{.*\}\Z|\A\[.*\]\Z/
|
9
|
+
begin
|
10
|
+
JSON.parse(str)
|
11
|
+
rescue JSON::ParserError => e
|
12
|
+
yield(e.message)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/xlgrep.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "xlgrep/version"
|
2
|
+
|
3
|
+
module Xlgrep
|
4
|
+
|
5
|
+
autoload :Context , "xlgrep/context"
|
6
|
+
autoload :InvalidJson, "xlgrep/invalid_json"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def method_missing(name, *args, &block)
|
10
|
+
mod = name.to_s.split(/_/).map(&:capitalize).join
|
11
|
+
if const_defined?(mod)
|
12
|
+
run([const_get(mod)], *args, &block)
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(predicates, files)
|
19
|
+
Context.new(predicates).execute(files)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
end
|
Binary file
|
data/spec/spec_helper.rb
ADDED
data/spec/xlgrep_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Xlgrep do
|
4
|
+
it 'should have a version number' do
|
5
|
+
Xlgrep::VERSION.should_not be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should do something useful' do
|
9
|
+
Dir.chdir(File.expand_path("..", __FILE__)) do
|
10
|
+
r = Xlgrep.invalid_json(Dir.glob("examples/**/*.*"))
|
11
|
+
r.should == [
|
12
|
+
{file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 2, data: "{'foo': 1}" , msg: "757: unexpected token at '{'foo': 1}'"},
|
13
|
+
{file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 3, data: "{\"foo\": 1, }", msg: "757: unexpected token at '{\"foo\": 1, }'"},
|
14
|
+
{file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 4, data: "{\"foo\", 1}" , msg: "757: unexpected token at '{\"foo\", 1}'"},
|
15
|
+
{file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 2, data: "['foo', 1]" , msg: "399: unexpected token at ''foo', 1]'"},
|
16
|
+
{file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 3, data: "[\"foo\", 1, ]", msg: "399: unexpected token at ']'"},
|
17
|
+
{file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 4, data: "[\"foo\": 1]" , msg: "399: unexpected token at ': 1]'"}
|
18
|
+
]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/xlgrep.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'xlgrep/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "xlgrep"
|
8
|
+
spec.version = Xlgrep::VERSION
|
9
|
+
spec.authors = ["akima"]
|
10
|
+
spec.email = ["akm2000@gmail.com"]
|
11
|
+
spec.description = %q{support to grep something in .xlsx files}
|
12
|
+
spec.summary = %q{support to grep something in .xlsx files}
|
13
|
+
spec.homepage = "https://github.com/groovenauts/xlgrep"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "roo", "~> 1.12.2"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xlgrep
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- akima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: roo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.12.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.12.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: support to grep something in .xlsx files
|
70
|
+
email:
|
71
|
+
- akm2000@gmail.com
|
72
|
+
executables:
|
73
|
+
- xlgrep
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .travis.yml
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/xlgrep
|
85
|
+
- lib/xlgrep.rb
|
86
|
+
- lib/xlgrep/context.rb
|
87
|
+
- lib/xlgrep/invalid_json.rb
|
88
|
+
- lib/xlgrep/version.rb
|
89
|
+
- spec/examples/json_example.xlsx
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/xlgrep_spec.rb
|
92
|
+
- xlgrep.gemspec
|
93
|
+
homepage: https://github.com/groovenauts/xlgrep
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.0.3
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: support to grep something in .xlsx files
|
117
|
+
test_files:
|
118
|
+
- spec/examples/json_example.xlsx
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
- spec/xlgrep_spec.rb
|
121
|
+
has_rdoc:
|