xlgrep 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f21c1e8346914b720e2a6541e519d6a87df463a
4
- data.tar.gz: d64b40c205c85ee67df865f49fab835312e59e5b
3
+ metadata.gz: bfeb38151e8a2c8b11cd8017c2d8e37f1426c1c1
4
+ data.tar.gz: b4946644f38765a04f90324579a0462edbc5c2c7
5
5
  SHA512:
6
- metadata.gz: 4eb942e0eb42bb9075f9de93dcbc8236b795fa8a3089b2ffa8cbfd0f7a7c1630bb7b4f2e997ca375a787c4e81e756bd40429e1d61e9c29d8999f50efcad97ab8
7
- data.tar.gz: a46ab34db12afe0b90d8c2673bd3363338af5c63ba332156865c09335ea598d1ad61cf3ed7c23234867f077eb277fc64ae530736b9639497a93c2cf607650df3
6
+ metadata.gz: 05c6ff8ece6dab044c8ce937de0409b7ba63e47a9ab0a91e16aa4a3fd2ea0649fd0122fe4d4ed829933b4bd91acee1b88813d4cb93396139ee42dc207e3ba609
7
+ data.tar.gz: c200dd85818e5571a868d30c17f7354f0a585dbbe6b22d3b73d8abd8e44ab17880449fb89cf789e6a3e886047911c480987dbdfc26d7e101f1211563fb35e30a
data/bin/xlgrep CHANGED
@@ -2,16 +2,4 @@
2
2
 
3
3
  require 'xlgrep'
4
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
5
+ Xlgrep.invalid_json(ARGV)
data/lib/xlgrep.rb CHANGED
@@ -4,6 +4,7 @@ module Xlgrep
4
4
 
5
5
  autoload :Context , "xlgrep/context"
6
6
  autoload :InvalidJson, "xlgrep/invalid_json"
7
+ autoload :SimpleFormatter, "xlgrep/simple_formatter"
7
8
 
8
9
  class << self
9
10
  def method_missing(name, *args, &block)
@@ -20,6 +21,4 @@ module Xlgrep
20
21
  end
21
22
  end
22
23
 
23
-
24
-
25
24
  end
@@ -1,9 +1,13 @@
1
+ require 'xlgrep'
2
+
1
3
  require 'roo'
4
+ require 'highline'
2
5
 
3
6
  module Xlgrep
4
7
  class Context
5
- def initialize(predicates)
8
+ def initialize(predicates, formatter = nil)
6
9
  @predicates = predicates
10
+ @formatter = formatter || SimpleFormatter.new
7
11
  end
8
12
 
9
13
  def book_for(file)
@@ -13,10 +17,11 @@ module Xlgrep
13
17
  BASE_CHAR_ORDER = 'A'.ord
14
18
 
15
19
  def execute(files)
16
- result = []
17
20
  files.each do |f|
18
21
  book = book_for(f)
19
22
  book.sheets.each do |sheet|
23
+ print_status("loading #{f} #{sheet}")
24
+
20
25
  book.default_sheet = sheet
21
26
  (book.first_row..book.last_row).each do |r|
22
27
  cells = book.row(r)
@@ -25,19 +30,32 @@ module Xlgrep
25
30
  pred.match(cell) do |msg|
26
31
  a, b = idx.divmod(26) # ('A'..'Z').length => 26
27
32
  x = (a > 0 ? (BASE_CHAR_ORDER + a).chr : "") + (BASE_CHAR_ORDER + b).chr
28
- result << {
33
+ print_status("")
34
+ @formatter.process({
29
35
  file: f, sheet: sheet,
30
36
  x: x, y: r,
31
37
  data: cell,
32
38
  msg: msg
33
- }
39
+ })
40
+ print_status("loading #{f} #{sheet}")
34
41
  end
35
42
  end
36
43
  end
37
44
  end
38
45
  end
46
+ # print_status(" loaded #{f}")
47
+ # puts
39
48
  end
40
- result
49
+ print_status("")
50
+ self
51
+ end
52
+
53
+ def print_status(s)
54
+ return unless $stdout.tty?
55
+ cols, rows = HighLine::SystemExtensions.terminal_size # [columns, lines]
56
+ slen = cols - s.bytesize
57
+ slen = 0 if slen < 0
58
+ $stdout.print("\r" + s + (" " * slen))
41
59
  end
42
60
 
43
61
  end
@@ -1,3 +1,5 @@
1
+ require 'xlgrep'
2
+
1
3
  require 'json'
2
4
 
3
5
  module Xlgrep
@@ -5,9 +7,9 @@ module Xlgrep
5
7
  class << self
6
8
 
7
9
  def match(str)
8
- if str =~ /\A\{.*\}\Z|\A\[.*\]\Z/
10
+ if str =~ /\A[\s\n\r]*(?:\{.*\}|\[.*\])[\s\n\r]*\Z/
9
11
  begin
10
- JSON.parse(str)
12
+ JSON.parse(str.strip)
11
13
  rescue JSON::ParserError => e
12
14
  yield(e.message)
13
15
  end
@@ -0,0 +1,18 @@
1
+ require 'xlgrep'
2
+
3
+ module Xlgrep
4
+ class SimpleFormatter
5
+ def initialize(io = nil)
6
+ @io = io || $stdout
7
+ end
8
+
9
+ def process(obj)
10
+ @io.puts "-" * 80
11
+ @io.puts "file : " << obj[:file]
12
+ @io.puts "sheet : " << obj[:sheet]
13
+ @io.puts "position: " << obj[:x] << obj[:y].to_s
14
+ @io.puts "cell : " << obj[:data]
15
+ @io.puts "msg : " << obj[:msg]
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Xlgrep
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
data/spec/xlgrep_spec.rb CHANGED
@@ -9,12 +9,20 @@ describe Xlgrep do
9
9
  Dir.chdir(File.expand_path("..", __FILE__)) do
10
10
  r = Xlgrep.invalid_json(Dir.glob("examples/**/*.*"))
11
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]'"}
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 Object", x: "B", y: 5, data: "\n\n{\"foo\", 1}", msg: "757: unexpected token at '{\"foo\", 1}'"},
16
+ {file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 6, data: " {\"foo\", 1}" , msg: "757: unexpected token at '{\"foo\", 1}'"},
17
+ {file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 7, data: "{\"foo\", 1} " , msg: "757: unexpected token at '{\"foo\", 1}'"},
18
+ {file: "examples/json_example.xlsx", sheet: "invalid Object", x: "B", y: 8, data: "{\"foo\", 1}\n\n", msg: "757: unexpected token at '{\"foo\", 1}'"},
19
+ {file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 2, data: "['foo', 1]" , msg: "399: unexpected token at ''foo', 1]'"},
20
+ {file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 3, data: "[\"foo\", 1, ]" , msg: "399: unexpected token at ']'"},
21
+ {file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 4, data: "[\"foo\": 1]" , msg: "399: unexpected token at ': 1]'"},
22
+ {file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 5, data: "\n\n[\"foo\": 1]", msg: "399: unexpected token at ': 1]'"},
23
+ {file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 6, data: " [\"foo\": 1]" , msg: "399: unexpected token at ': 1]'"},
24
+ {file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 7, data: "[\"foo\": 1] " , msg: "399: unexpected token at ': 1]'"},
25
+ {file: "examples/json_example.xlsx", sheet: "invalid Array" , x: "B", y: 8, data: "[\"foo\": 1]\n\n", msg: "399: unexpected token at ': 1]'"},
18
26
  ]
19
27
  end
20
28
  end
data/xlgrep.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "roo", "~> 1.12.2"
22
+ spec.add_runtime_dependency "highline"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.12.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -85,6 +99,7 @@ files:
85
99
  - lib/xlgrep.rb
86
100
  - lib/xlgrep/context.rb
87
101
  - lib/xlgrep/invalid_json.rb
102
+ - lib/xlgrep/simple_formatter.rb
88
103
  - lib/xlgrep/version.rb
89
104
  - spec/examples/json_example.xlsx
90
105
  - spec/spec_helper.rb