icersplicer 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/icersplicer +136 -0
  3. data/lib/icersplicer.rb +98 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf3bfe4bb8acc26367b7c99982a5016137f2bf9f
4
+ data.tar.gz: ac26602340bd429202c1d902f4dead4af880bbe5
5
+ SHA512:
6
+ metadata.gz: 8bb8bb496f91f8f5c39721a3b4453883089e5da8191cd5d145f91873e1fa952ecf0eba051801c8b390ee11ef7029b655a79a441c2fefb4e7415502c7180ee3d6
7
+ data.tar.gz: 1e82a2c5aca81e382571117d66393d988b175104b6b1063c503993977c6f6f46419bace34a7c7dad26abf399dfb5f43e7d9a886f0603384805f0dbad2e772979
data/bin/icersplicer ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/ruby
2
+ ########################################################################
3
+ #
4
+ # Author: Brian Hood
5
+ # Name: Icersplicer
6
+ #
7
+ # Description:
8
+ # Text processing with power with very minimal mruby for performance
9
+ # that only has a File class extension mruby-io
10
+ #
11
+ # Why: for processing large datasets quickly.
12
+ ########################################################################
13
+
14
+ require 'getoptlong'
15
+ require 'pp'
16
+ require File.expand_path(File.join(
17
+ File.dirname(__FILE__),
18
+ "../lib/icersplicer.rb"))
19
+
20
+ include Icersplicer
21
+
22
+ ARGV[0] = "--help" if ARGV[0] == nil
23
+
24
+ opts = GetoptLong.new(
25
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
26
+ [ '--lineoffset', '-l', GetoptLong::OPTIONAL_ARGUMENT],
27
+ [ '--linelimit', '-n', GetoptLong::REQUIRED_ARGUMENT],
28
+ [ '--incrementlimit', '-i', GetoptLong::OPTIONAL_ARGUMENT],
29
+ [ '--inputfile', '-f', GetoptLong::REQUIRED_ARGUMENT],
30
+ [ '--skiplines', '-s', GetoptLong::OPTIONAL_ARGUMENT],
31
+ [ '--quiet', '-q', GetoptLong::OPTIONAL_ARGUMENT],
32
+ [ '--outputfile', '-o', GetoptLong::OPTIONAL_ARGUMENT],
33
+ [ '--countlines', '-c', GetoptLong::OPTIONAL_ARGUMENT]
34
+ )
35
+
36
+ opts.each do |opt, arg|
37
+ case opt
38
+ when '--help'
39
+ helper = "\e[1;34mWelcome to Icersplicer\e[0m\ \n"
40
+ helper << "\e[1;34m=====================\e[0m\ \n"
41
+ helper << %q[
42
+ -h, --help:
43
+ show help
44
+
45
+ Example:
46
+
47
+ icersplicer -f inputfile --lineoffset 0 --linelimit 10 -s 3,6,9 -o outputfile
48
+
49
+ ]
50
+ puts helper
51
+ exit
52
+ when '--lineoffset'
53
+ @line_offset = arg.to_i
54
+ when '--linelimit'
55
+ @line_limit = arg.to_i
56
+ when '--incrementlimit'
57
+ @increment_limit = arg.to_i
58
+ when '--inputfile'
59
+ @inputfile = arg.to_s
60
+ when '--outputfile'
61
+ @outputfile = arg.to_s
62
+ puts "Outputfile: #{@outputfile}"
63
+ when '--skiplines'
64
+ @skip_lines = Array.new
65
+ arg.to_s.split(",").each {|n| @skip_lines << n.to_i }
66
+ when '--quiet'
67
+ if arg == "true"
68
+ @quiet_mode = true
69
+ else
70
+ @quiet_mode = false
71
+ end
72
+ when '--countlines'
73
+ @countlines = true
74
+ end
75
+ end
76
+
77
+ unless instance_variable_defined?("@line_offset")
78
+ lineoffset = 0
79
+ else
80
+ lineoffset = @line_offset
81
+ end
82
+
83
+ unless instance_variable_defined?("@line_limit")
84
+ linelimit = 0
85
+ else
86
+ linelimit = @line_limit
87
+ end
88
+
89
+ increment_offset = 0
90
+ unless instance_variable_defined?("@increment_limit")
91
+ increment_limit = 1
92
+ else
93
+ increment_limit = @increment_limit
94
+ end
95
+ linecounter = 0
96
+ quietmode = false | @quiet_mode
97
+
98
+ inputfile = @inputfile
99
+ outputfile = @outputfile
100
+
101
+ if @countlines == true
102
+ countlines(inputfile)
103
+ exit
104
+ end
105
+
106
+ unless File.exist?("#{inputfile}")
107
+ puts "Input filename / location doesn't exist... ?"
108
+ exit
109
+ end
110
+
111
+ File.open(inputfile) {|n|
112
+ n.each_line {|data|
113
+ data_orig = data.clone
114
+ unless lineoffset > increment_offset
115
+ unless linelimit == 0
116
+ unless increment_limit > linelimit
117
+ print_to_screen(linecounter, text_highlighter(data), quietmode) unless skip(linecounter)
118
+ if instance_variable_defined?("@outputfile")
119
+ processdata(data_orig, outputfile, quietmode) unless skip(linecounter)
120
+ end
121
+ end
122
+ else
123
+ print_to_screen(linecounter, text_highlighter(data), quietmode) unless skip(linecounter)
124
+ if instance_variable_defined?("@outputfile")
125
+ processdata(data_orig, outputfile, quietmode) unless skip(linecounter)
126
+ end
127
+ end
128
+ increment_limit += 1
129
+ end
130
+ increment_offset += 1
131
+ linecounter += 1
132
+ }
133
+ }
134
+
135
+ closefile if instance_variable_defined?("@exp")
136
+ stats(inputfile, outputfile)
@@ -0,0 +1,98 @@
1
+ ########################################################################
2
+ #
3
+ # Author: Brian Hood
4
+ # Name: Icersplicer
5
+ #
6
+ # Description:
7
+ # Main module for file processing
8
+ #
9
+ #
10
+ ########################################################################
11
+
12
+ module Icersplicer
13
+
14
+ module VERSION #:nodoc:
15
+
16
+ MAJOR = 0
17
+ MINOR = 1
18
+ TINY = 4
19
+ CODENAME = "Icestorm !"
20
+
21
+ STRING = [MAJOR, MINOR, TINY].join('.')
22
+
23
+ end
24
+
25
+ @@nfile = 0
26
+ @@exp = nil
27
+
28
+ def text_highlighter(text)
29
+ keys = ["Ln:", "SELECT", "CREATE TABLE", "UPDATE", "DELETE", "INSERT", "FROM", "OFFSET", "GROUP BY", "HAVING", "ORDER BY",
30
+ "ALTER USER", "ALTER TABLE", "COPY", "INTO", "VALUES", "DELIMITERS", "STDIN", "CREATE USER", "WITH", "USING",
31
+ "CREATE INDEX", "CONSTRAINT", "ALTER INDEX", "INTEGER", "CHAR", "CLOB", "VARCHAR", "STRING", "DEFAULT", "NULL", "NOT",
32
+ "RECORDS", "KEY", "PRIMARY", "FOREIGN", "BIGINT", "MERGE", "REMOTE", "DROP TABLE", "SET SCHEMA", "CREATE SCHEMA",
33
+ "ALTER SCHEMA", "ADD", "TABLE", "CREATE SEQUENCE", "ALTER SEQUENCE"]
34
+ cpicker = [2,3,4,1,7,5,6] # Just a selection of colours
35
+ keys.each {|n|
36
+ text.gsub!("#{n}", "\e[4;3#{cpicker[rand(cpicker.size)]}m#{n}\e[0m\ \e[0;32m".strip)
37
+ }
38
+ return text
39
+ end
40
+
41
+ def countlines(inputfile)
42
+ lines = 0
43
+ unless inputfile == nil
44
+ if File.exists?(inputfile)
45
+ File.open(inputfile) {|n|
46
+ n.each_line {
47
+ lines += 1
48
+ }
49
+ }
50
+ puts "Filename: #{inputfile} Total Line Count: #{lines}"
51
+ end
52
+ end
53
+ end
54
+
55
+ def skip(line)
56
+ begin
57
+ line_element = @skip_lines.index(line)
58
+ if line_element != nil
59
+ skiper = @skip_lines[line_element]
60
+ end
61
+ rescue NoMethodError
62
+ return nil
63
+ end
64
+ return skiper
65
+ end
66
+
67
+ def print_to_screen(linenum, text, quiet)
68
+ puts "\e[1;33mLn: #{linenum}:\e[0m\ #{text}" unless quiet == true
69
+ end
70
+
71
+ def openfile(outputfile)
72
+ puts "Openfile: #{outputfile}"
73
+ @@exp = File.open("#{outputfile}", 'w')
74
+ end
75
+
76
+ def writefile(data)
77
+ @@exp.write(data)
78
+ end
79
+
80
+ def closefile
81
+ @@exp.close
82
+ puts "Closing file: #{outputfile}"
83
+ end
84
+
85
+ def processdata(data, outputfile, quietmode)
86
+ openfile(outputfile) if @@nfile == 0
87
+ writefile(data)
88
+ @@nfile += 1
89
+ end
90
+
91
+ def stats(inputfile, outputfile)
92
+ print "Inputfile lines: "
93
+ countlines(inputfile)
94
+ #print "Outputfile lines: "
95
+ #countlines(outputfile)
96
+ end
97
+
98
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: icersplicer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Brian Hood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Text file manipulation similar to UNIX tools like cat / head / tail
14
+ email: brianh6854@googlemail.com
15
+ executables:
16
+ - icersplicer
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/icersplicer
21
+ - lib/icersplicer.rb
22
+ homepage: https://github.com/puppetpies/icersplicer
23
+ licenses:
24
+ - GPLv2
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.2.2
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Icersplicer
46
+ test_files: []