icersplicer 1.0.0 → 1.0.6

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: 901e149dd77a8c15cc4af20745aa37551a79efd2
4
- data.tar.gz: 20ae40614d6046d799bcedbf48b290590ec52816
3
+ metadata.gz: 828fde885629227694e9908fbc47fdf5c19fdb04
4
+ data.tar.gz: 7cddde3b73f6932e7b54a6f766ab3418bc2a6895
5
5
  SHA512:
6
- metadata.gz: 2fc50ae99150351682ffc58541cea694719d482b9ed6b89375d96b49ccfec0b9d3abab4e5103295ad4501a38e4c3ad1acd77155d1d222c4ee274e0f8c636f1a9
7
- data.tar.gz: 19f685820c5b6c8b64bb544dfb2fddb54abc0e5f1231d189221fffd7cf5cfc64d6e234c06e1a4c4456601776982361d0591d0faf19ccb4072f46a4156f819e14
6
+ metadata.gz: cd69d5421d3d4d20d1f77d7499339046192bc1ac8bb3f72b3bb773e0a0945d9da3973661693e1780b5e6328c0f556565bb65b4e5ff720b231565bc606a6622c5
7
+ data.tar.gz: 02808a1982b5022f9fdaf56c53e2cd8ce9147c8d4f49b37569f74e3a21bc70719052f7f92086babfa97bce6b9d807d984fda5527b5b51d5c2578d86a39d612fb
data/bin/icersplicer CHANGED
@@ -17,6 +17,9 @@ require 'getoptlong'
17
17
  require 'walltime'
18
18
  require 'pp'
19
19
 
20
+ require File.expand_path(File.join(
21
+ File.dirname(__FILE__),
22
+ "../lib/globutils.rb"))
20
23
  require File.expand_path(File.join(
21
24
  File.dirname(__FILE__),
22
25
  "../lib/icersplicer.rb"))
@@ -24,6 +27,7 @@ require File.expand_path(File.join(
24
27
  File.dirname(__FILE__),
25
28
  "../lib/version.rb"))
26
29
 
30
+ include GlobUtils
27
31
  include Icersplicer
28
32
 
29
33
  trap("INT") {
@@ -199,9 +203,11 @@ if @countlines == true
199
203
  end
200
204
 
201
205
  inputfile.split(",").each {|f|
202
- unless File.exist?("#{f}")
203
- raise ArgumentError, "Input filename #{f} / location doesn't exist... ?"
204
- exit
206
+ unless f =~ FILE_EXT_REGEXP
207
+ unless File.exist?("#{f}")
208
+ raise ArgumentError, "Input filename #{f} / location doesn't exist... ?"
209
+ exit
210
+ end
205
211
  end
206
212
  }
207
213
 
@@ -211,7 +217,13 @@ unless instance_variable_defined?("@nostats")
211
217
  timer.watch('start')
212
218
  end
213
219
  begin
214
- inputfile.split(",").each {|f|
220
+ # Regular file / glob mask processor
221
+ filenames = joinfilenames(buildfilelist(inputfile))
222
+ # Iterator for file / file list
223
+ filenames.split(",").each {|f|
224
+ linecounter = 0
225
+ ice.reset_screen
226
+ puts "> Filename: #{f} <"
215
227
  File.open(f) {|n|
216
228
  n.each_line {|data|
217
229
  data_orig = data.clone
data/lib/globutils.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'pp'
2
+
3
+ module GlobUtils
4
+
5
+ =begin
6
+
7
+ Glob Example
8
+
9
+ filenames = "/home/brian/Projects/icersplicer/bin/icersplicer,/home/brian/Projects/icersplicer/lib/version.rb,/home/brian/Projects/threatmonitor/*.rb,/home/brian/Projects/Walltime/*"
10
+ files = buildfilelist(filenames)
11
+
12
+ =end
13
+
14
+ FILE_EXT_REGEXP = /\/*.([a-z]|[A-Z])+$/
15
+ FILE_WILDCARD_REGEXP = /\*.([a-z]|[A-Z])+$/
16
+ @@debug = 0
17
+
18
+ def glob(f)
19
+ puts "String end: #{f[f.size - 1]}" if @@debug == 1
20
+ unless f[f.size - 1] == "*"
21
+ files = Hash.new
22
+ globcounter = 0
23
+ fileext = f.split(".")[f.split(".").size - 1] # Extract Extension from string for example .rb
24
+ fileglob = f.gsub(FILE_EXT_REGEXP, "/**/*.#{fileext}").gsub("/*/", "/") # Match to find anything file extension / replace Glob using fileext
25
+ begin
26
+ # Send created glob into Dir.glob
27
+ Dir.glob(fileglob) {|n|
28
+ files.update({globcounter => n})
29
+ globcounter += 1
30
+ }
31
+ rescue
32
+ raise ArgumentError, "Invalid Glob"
33
+ end
34
+ return files
35
+ else
36
+ raise ArgumentError, "Please specify file extension for glob i.e *.html"
37
+ end
38
+ end
39
+
40
+ def joinfilenames(rollfiles)
41
+ filenames = String.new
42
+ rollfiles.each {|n|
43
+ filenames << "#{n[1]},"
44
+ }
45
+ filenames.gsub!(%r=,$=, "")
46
+ end
47
+
48
+ def buildfilelist(inputfile)
49
+ rollfiles = Hash.new
50
+ rollcounter = 0
51
+ inputfile.split(",").each {|f|
52
+ puts "Filename: #{f}" if @@debug == 1
53
+ unless f =~ FILE_WILDCARD_REGEXP
54
+ rollfiles.update({rollcounter => f})
55
+ rollcounter += 1
56
+ puts "Regular File" if @@debug == 1
57
+ else
58
+ puts "Glob File Mask" if @@debug == 1
59
+ g = glob(f)
60
+ g.each {|n|
61
+ rollfiles.update({rollcounter => n[1]})
62
+ rollcounter += 1
63
+ }
64
+ end
65
+ }
66
+ return rollfiles
67
+ end
68
+
69
+ end
data/lib/icersplicer.rb CHANGED
@@ -10,6 +10,7 @@
10
10
  ########################################################################
11
11
  require 'file-tail'
12
12
 
13
+
13
14
  module Icersplicer
14
15
 
15
16
  class FileProcessor
@@ -79,9 +80,9 @@ module Icersplicer
79
80
  end
80
81
 
81
82
  def text_highlighter(text)
82
- @keys ||= load_keywords("#{@keywordsfile}")
83
- unless @keys.class == Hash
84
- @keys = {0 => "Ln:",
83
+ keys ||= load_keywords("#{@keywordsfile}")
84
+ unless keys.class == Hash
85
+ keys = {0 => "Ln:",
85
86
  1 => "SELECT",
86
87
  2 => "CREATE TABLE",
87
88
  3 => "UPDATE",
@@ -89,7 +90,7 @@ module Icersplicer
89
90
  5 => "INSERT"}
90
91
  end
91
92
  cpicker = [2,3,4,1,7,5,6] # Just a selection of colours
92
- @keys.each {|n|
93
+ keys.each {|n|
93
94
  if n[1].split("##")[1] == nil
94
95
  text.gsub!("#{n[1]}", "\e[4;3#{cpicker[rand(cpicker.size)]}m#{n[1]}\e[0m\ \e[0;32m")
95
96
  else
@@ -122,20 +123,20 @@ module Icersplicer
122
123
  skip_lines = Hash.new
123
124
  skipcounter = 0
124
125
  filter.to_s.split(",").each {|n|
125
- skip_lines.update({skipcounter => n.to_i})
126
- # Allow line ranges
127
- min = n.split("-")[0].to_i
128
- max = n.split("-")[1].to_i
129
- puts "Min: #{min} Max: #{max}" if @debug >= 2
130
- unless n.split("-")[1] == nil
131
- if min > max
132
- raise RangeError, "Range Error: Minimun value can't be more than Maxiumun Range value"
133
- end
134
- min.upto(max) {|s|
135
- skip_lines.update({skipcounter => s}) unless skip_lines[skip_lines.size - 1] == s
136
- skipcounter += 1
137
- }
126
+ skip_lines.update({skipcounter => n.to_i})
127
+ # Allow line ranges
128
+ min = n.split("-")[0].to_i
129
+ max = n.split("-")[1].to_i
130
+ puts "Min: #{min} Max: #{max}" if @debug >= 2
131
+ unless n.split("-")[1] == nil
132
+ if min > max
133
+ raise RangeError, "Range Error: Minimun value can't be more than Maxiumun Range value"
138
134
  end
135
+ min.upto(max) {|s|
136
+ skip_lines.update({skipcounter => s}) unless skip_lines[skip_lines.size - 1] == s
137
+ skipcounter += 1
138
+ }
139
+ end
139
140
  skipcounter += 1
140
141
  }
141
142
  return skip_lines
data/lib/version.rb CHANGED
@@ -4,8 +4,8 @@ module Icersplicer
4
4
  module VERSION #:nodoc:
5
5
  MAJOR = 1
6
6
  MINOR = 0
7
- TINY = 0
8
- CODENAME = "Ice Fox!"
7
+ TINY = 6
8
+ CODENAME = "Icey Blizzard!"
9
9
  STRING = [MAJOR, MINOR, TINY].join('.')
10
10
  end
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icersplicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Hood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: walltime
@@ -50,6 +50,7 @@ files:
50
50
  - examples/files/voc_dump.sql
51
51
  - examples/keywords-ruby.ice
52
52
  - examples/keywords.ice
53
+ - lib/globutils.rb
53
54
  - lib/icersplicer.rb
54
55
  - lib/version.rb
55
56
  homepage: https://github.com/puppetpies/icersplicer