icersplicer 0.3.6 → 0.4.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/icersplicer +33 -31
  3. data/lib/icersplicer.rb +37 -6
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79a6b544dd7773a013878c6e2ba86254a45dd389
4
- data.tar.gz: 7acbff17920844192fb8a3f5d8e97be1a156d569
3
+ metadata.gz: 6e74103ad7acd91e846845928dee5cd14a68b2a0
4
+ data.tar.gz: e99b949b976c0e3ee96f8b707db4dd5db1395b60
5
5
  SHA512:
6
- metadata.gz: 78d1cfaf9f36116a67727f820e49277f69590d40763df5cd2951f281e0c01ca51ea3a2007851a620877be6cab5250ced548f77f714ff5acfb717858a861be627
7
- data.tar.gz: 2262de63b30956f95f8dc41bcfdc216d50cb6120c8fcf9fbd9f45358a2bd4a4e50e371df9f6c671fb378592b18e07061b8983be988b5d165740f82bd737d62c2
6
+ metadata.gz: 8a1bac8788290a8f83ae8117ff9a8d69c199e38216c880eaa3da7f754e28984d098e889978917712405d63a10305eafd8cca0f78042a205b35cfe9805e7c18ca
7
+ data.tar.gz: 7e8ab2a5375746f32a6cb0ad556569e0d948b4300c66ebe5a2afa97f24e1ec2c8904d4d90ab041bc7f4f3e446b966fbdac9c4176bdc1bf00c332bae43fcae686
data/bin/icersplicer CHANGED
@@ -13,7 +13,9 @@
13
13
  ########################################################################
14
14
 
15
15
  require 'getoptlong'
16
+ require 'walltime'
16
17
  require 'pp'
18
+
17
19
  require File.expand_path(File.join(
18
20
  File.dirname(__FILE__),
19
21
  "../lib/icersplicer.rb"))
@@ -36,7 +38,9 @@ opts = GetoptLong.new(
36
38
  [ '--outputfile', '-o', GetoptLong::OPTIONAL_ARGUMENT],
37
39
  [ '--countlines', '-c', GetoptLong::OPTIONAL_ARGUMENT],
38
40
  [ '--grep', '-g', GetoptLong::REQUIRED_ARGUMENT],
39
- [ '--nohighlighter', '-t', GetoptLong::NO_ARGUMENT ]
41
+ [ '--nohighlighter', '-t', GetoptLong::NO_ARGUMENT ],
42
+ [ '--search', '-1', GetoptLong::REQUIRED_ARGUMENT],
43
+ [ '--replace', '-2', GetoptLong::REQUIRED_ARGUMENT]
40
44
  )
41
45
 
42
46
  opts.each do |opt, arg|
@@ -57,7 +61,9 @@ opts.each do |opt, arg|
57
61
  --countlines '-c' Counts the lines of a file
58
62
  --grep '-g' Filter data
59
63
  --nohighlighter '-t' NO ARGUMENTS ( Turns off syntax hightlighting )
60
-
64
+ --search '-1' Text to search for
65
+ --replace '-2' Replacement string
66
+
61
67
  Example:
62
68
 
63
69
  icersplicer -f inputfile --lineoffset 0 --linelimit 10 -s 3,6,9,10-15 -o outputfile
@@ -81,26 +87,7 @@ Written by Brian Hood
81
87
  @outputfile = arg.to_s
82
88
  puts "Outputfile: #{@outputfile}"
83
89
  when '--skiplines'
84
- @skip_lines = Array.new
85
- arg.to_s.split(",").each {|n|
86
- @skip_lines << n.to_i
87
- # Allow line ranges
88
- min = n.split("-")[0].to_i
89
- max = n.split("-")[1].to_i
90
- unless n.split("-")[1] == nil
91
- begin
92
- if min > max and max != 0
93
- return false
94
- end
95
- rescue
96
- puts "Range Error: Minimun value can't be more than Maxiumun Range value"
97
- exit
98
- end
99
- min.upto(max) {|s|
100
- @skip_lines << s unless @skip_lines[@skip_lines.size - 1] == s
101
- }
102
- end
103
- }
90
+ @skip_lines = skip_processor(arg)
104
91
  when '--skipblank'
105
92
  @skipblank = "SKIP"
106
93
  when '--quiet'
@@ -115,9 +102,25 @@ Written by Brian Hood
115
102
  @grep = arg.to_s
116
103
  when '--nohighlighter'
117
104
  @nohighlighter = "OFF"
105
+ when '--search'
106
+ @search = arg.to_s
107
+ when '--replace'
108
+ @replace = arg.to_s
118
109
  end
119
110
  end
120
111
 
112
+ if instance_variable_defined?("@search")
113
+ search = @search
114
+ if instance_variable_defined?("@replace")
115
+ replace = @replace
116
+ search_and_replace = true
117
+ else
118
+ puts "Replace string required to use search / replace features..."
119
+ exit
120
+ end
121
+ end
122
+
123
+
121
124
  unless instance_variable_defined?("@line_offset")
122
125
  lineoffset = 0
123
126
  else
@@ -152,19 +155,16 @@ unless File.exist?("#{inputfile}")
152
155
  exit
153
156
  end
154
157
 
155
- def text_processor(data)
156
- unless instance_variable_defined?("@nohighlighter")
157
- data = text_highlighter(data)
158
- return data
159
- else
160
- return data
161
- end
162
- end
163
-
158
+ timer = Stopwatch.new
159
+ timer.watch('start')
164
160
  begin
165
161
  File.open(inputfile) {|n|
166
162
  n.each_line {|data|
167
163
  data_orig = data.clone
164
+ if search_and_replace == true
165
+ data_orig.gsub!("#{search}", "#{replace}")
166
+ data.gsub!("#{search}", "#{replace}")
167
+ end
168
168
  unless lineoffset > increment_offset
169
169
  unless linelimit == 0
170
170
  unless increment_limit > linelimit
@@ -198,3 +198,5 @@ rescue Errno::EPIPE
198
198
  end
199
199
  closefile if instance_variable_defined?("@exp")
200
200
  stats(inputfile, outputfile)
201
+ timer.watch('stop')
202
+ timer.print_stats
data/lib/icersplicer.rb CHANGED
@@ -13,8 +13,8 @@ module Icersplicer
13
13
 
14
14
  module VERSION #:nodoc:
15
15
  MAJOR = 0
16
- MINOR = 3
17
- TINY = 6
16
+ MINOR = 4
17
+ TINY = 2
18
18
  CODENAME = "Ice Axe !"
19
19
  STRING = [MAJOR, MINOR, TINY].join('.')
20
20
  end
@@ -48,7 +48,16 @@ module Icersplicer
48
48
  return false
49
49
  end
50
50
  end
51
-
51
+
52
+ def text_processor(data)
53
+ unless instance_variable_defined?("@nohighlighter")
54
+ data = text_highlighter(data)
55
+ return data
56
+ else
57
+ return data
58
+ end
59
+ end
60
+
52
61
  def text_highlighter(text)
53
62
  keys = load_keywords("#{@@keywordsfile}")
54
63
  if keys == false
@@ -64,9 +73,7 @@ module Icersplicer
64
73
  text.gsub!("#{n}", "\e[4;3#{cpicker[rand(cpicker.size)]}m#{n}\e[0m\ \e[0;32m".strip)
65
74
  else
66
75
  name = n.split("##")[1].split("=")[1]
67
- #puts "Colour: #{name} #{COLOURS[name]}"
68
76
  cnum = COLOURS[name].to_i
69
- #puts "NVal: #{n}"
70
77
  nval = n.split("##")[0]
71
78
  text.gsub!("#{nval}", "\e[4;3#{cnum}m#{nval}\e[0m\ \e[0;32m".strip)
72
79
  end
@@ -88,7 +95,31 @@ module Icersplicer
88
95
  end
89
96
  end
90
97
  end
91
-
98
+
99
+ def skip_processor(filter)
100
+ skip_lines = Array.new
101
+ filter.to_s.split(",").each {|n|
102
+ skip_lines << n.to_i
103
+ # Allow line ranges
104
+ min = n.split("-")[0].to_i
105
+ max = n.split("-")[1].to_i
106
+ unless n.split("-")[1] == nil
107
+ begin
108
+ if min > max and max != 0
109
+ return false
110
+ end
111
+ rescue
112
+ puts "Range Error: Minimun value can't be more than Maxiumun Range value"
113
+ exit
114
+ end
115
+ min.upto(max) {|s|
116
+ skip_lines << s unless skip_lines[skip_lines.size - 1] == s
117
+ }
118
+ end
119
+ }
120
+ return skip_lines
121
+ end
122
+
92
123
  def skip(line)
93
124
  begin
94
125
  line_element = @skip_lines.index(line)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icersplicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Hood
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-01-17 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: walltime
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.5
13
27
  description: Text file manipulation similar to UNIX tools like cat / head / tail
14
28
  email: brianh6854@googlemail.com
15
29
  executables: