parsefiles 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +8 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/parsefiles +9 -0
- data/lib/.DS_Store +0 -0
- data/lib/cli.rb +52 -0
- data/lib/parsefiles/file_ops.rb +41 -0
- data/lib/parsefiles/folders.rb +85 -0
- data/lib/parsefiles/parse.rb +33 -0
- data/lib/parsefiles/utils.rb +32 -0
- data/lib/parsefiles/version.rb +3 -0
- data/lib/parsefiles.rb +4 -0
- data/parsefiles.gemspec +27 -0
- data/spec/.DS_Store +0 -0
- data/spec/fixtures/compressed.tar.gz +0 -0
- data/spec/fixtures/compressed.zip +0 -0
- data/spec/fixtures/testfile.txt +2 -0
- data/spec/fixtures/testfile2.txt +0 -0
- data/spec/lib/cli_spec.rb +12 -0
- data/spec/lib/parsefiles/file_spec.rb +46 -0
- data/spec/lib/parsefiles/folders_spec.rb +67 -0
- data/spec/lib/parsefiles/utils_spec.rb +32 -0
- data/spec/spec_helper.rb +16 -0
- data/tasks.TODO +7 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b06a9a7c1730baddc47203dd32b17432f42bc48
|
4
|
+
data.tar.gz: 21d776d817820a84c9480966a2f35e32f17a57cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7cf2a276067b81ac8663f5af2378dd958718d31a801993d101b14e7cd5956539aa8ad71f90e256aeb6d230c8d129d6b92a2f4e09fddefcc9de892dc25cf84fa7
|
7
|
+
data.tar.gz: 7d60c3a5640c6d2274dee16e3cbafee37b921edc7cafb0b8e2b96894b2202eeccf0a5fa16077aaa78f7f302f117fc505f85fae77faea86cbf9dde66557e480d2
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Simpson
|
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
|
+
# Parsefiles
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'parsefiles'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install parsefiles
|
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
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/parsefiles
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'thor'
|
3
|
+
require 'thor/runner'
|
4
|
+
|
5
|
+
module Parsefiles
|
6
|
+
module CLI
|
7
|
+
class Main < Thor
|
8
|
+
|
9
|
+
desc 'version', 'Version of the Merge utility'
|
10
|
+
def version
|
11
|
+
require 'parsefiles/version'
|
12
|
+
say Parsefiles::VERSION
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'find', 'Find expression within specified text files'
|
16
|
+
long_desc <<-LONGDESC
|
17
|
+
Examples:
|
18
|
+
\x5 parsefiles find -d 2 -p simpson ./
|
19
|
+
\x5 => Search the current folder starting 2 days back for simpson.
|
20
|
+
\x5\x5 parsefiles find -s 08-01-2014 -e 08-03-2014 -p simpson ./
|
21
|
+
\x5 => Search between the 2 given dates for simpson
|
22
|
+
\x5\x5 parsefiles find -p simpson ./ /tmp/
|
23
|
+
\x5=> Search the current folder and tmp folder for simpson with today's date.
|
24
|
+
LONGDESC
|
25
|
+
method_option :days_back, aliases: '-d', type: 'string', default: '1', desc: 'number of days back to search'
|
26
|
+
method_option :start_date, aliases: '-s', type: 'string', default: Date.today.strftime('%m-%d-%Y'), desc: 'start date to begin file search from'
|
27
|
+
method_option :end_date, aliases: '-e', type: 'string', default: Date.today.strftime('%m-%d-%Y'), desc: 'end date to finish file search from'
|
28
|
+
method_option :pattern, aliases: '-p', type: 'string', default: ' ', desc: 'pattern to search for', :required => true
|
29
|
+
|
30
|
+
def find(*folders)
|
31
|
+
begin
|
32
|
+
folders = folders.split unless folders.class == Array
|
33
|
+
folders.each do |folder|
|
34
|
+
f = Parsefiles::Folders.new(folder,options)
|
35
|
+
files = f.get_files_in_range
|
36
|
+
files.each do |file|
|
37
|
+
puts "================================================"
|
38
|
+
puts "Reading : #{file}"
|
39
|
+
puts "================================================"
|
40
|
+
parse = Parsefiles::FileOps.new(file,options[:pattern])
|
41
|
+
parse.parse_file
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue Exception => e
|
45
|
+
say e.message, :red
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'parse'
|
2
|
+
|
3
|
+
module Parsefiles
|
4
|
+
class FileOps
|
5
|
+
|
6
|
+
include Parse
|
7
|
+
|
8
|
+
attr_accessor :file,:pattern
|
9
|
+
|
10
|
+
def initialize(file,pattern)
|
11
|
+
@file = file
|
12
|
+
@pattern = pattern
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_file_type
|
16
|
+
File.extname(@file).gsub!(/\./,'')
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_file
|
20
|
+
method_name = "parse_#{get_file_type}"
|
21
|
+
self.send method_name.to_sym
|
22
|
+
end
|
23
|
+
|
24
|
+
def match_line(line)
|
25
|
+
line = encode_string(line)
|
26
|
+
p line if line.match(@pattern)
|
27
|
+
end
|
28
|
+
|
29
|
+
def encode_string(input)
|
30
|
+
encode_it(input)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def encode_it(input)
|
36
|
+
input.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace, :replace => '').encode('UTF-8')
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'date'
|
2
|
+
require_relative 'utils'
|
3
|
+
|
4
|
+
module Parsefiles
|
5
|
+
class Folders
|
6
|
+
|
7
|
+
include Utils
|
8
|
+
|
9
|
+
attr_accessor :folder, :files
|
10
|
+
|
11
|
+
VALID_TYPES = "{txt,log,gz}"
|
12
|
+
|
13
|
+
def initialize(folder,options={})
|
14
|
+
@folder = check_location(folder)
|
15
|
+
@files = get_files_with_date
|
16
|
+
@options = options
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_location(folder)
|
20
|
+
if folder.match(/.*\.log$|txt$|gz$/i)
|
21
|
+
"./#{folder}"
|
22
|
+
else
|
23
|
+
folder = remove_trailing_slash(folder)
|
24
|
+
"#{folder}/*."+VALID_TYPES
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove_trailing_slash(folder)
|
29
|
+
folder.gsub(/(.*)\/$/,'\1')
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_files_in_range
|
33
|
+
start_date = get_start_date
|
34
|
+
end_date = get_end_date
|
35
|
+
|
36
|
+
result = []
|
37
|
+
@files.each_with_index do |file,index|
|
38
|
+
result << file[0] if Folders.date_in_range(file[1],start_date,end_date)
|
39
|
+
end
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_start_date
|
44
|
+
if @options["days_back"].to_i > 1
|
45
|
+
days_back
|
46
|
+
else
|
47
|
+
start_date
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_end_date
|
52
|
+
Folders.validate_date_format(@options["end_date"])
|
53
|
+
@options["end_date"] if @options["end_date"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def calc_start_date(days_back)
|
57
|
+
date = Date.today - days_back
|
58
|
+
date.strftime('%m-%d-%Y')
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def days_back
|
64
|
+
calc_start_date(@options[:days_back].to_i)
|
65
|
+
end
|
66
|
+
|
67
|
+
def start_date
|
68
|
+
Folders.validate_date_format(@options["start_date"])
|
69
|
+
@options["start_date"] if @options["start_date"]
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns an array with file and date in unix time format ['file.txt','40001245']
|
73
|
+
def get_files_with_date
|
74
|
+
file_list = Dir.glob(@folder)
|
75
|
+
result = []
|
76
|
+
file_list.reduce([]) do |file_stats,file|
|
77
|
+
file_stats = Array.new
|
78
|
+
file_stats << file
|
79
|
+
file_stats << Folders.unix_ts(file)
|
80
|
+
result << file_stats
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
|
3
|
+
module Parsefiles
|
4
|
+
module Parse
|
5
|
+
|
6
|
+
|
7
|
+
#Handles tar.gz and zip
|
8
|
+
|
9
|
+
def parse_gz
|
10
|
+
File.open(file, "r") do |f|
|
11
|
+
gz = Zlib::GzipReader.new(f)
|
12
|
+
gz.each_line do |line|
|
13
|
+
match_line(line.chomp)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_zip
|
19
|
+
#TODO
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_log
|
23
|
+
File.open(@file, "r") do |open_file|
|
24
|
+
open_file.each do |line|
|
25
|
+
match_line(line.chomp)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :parse_txt, :parse_log
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Parsefiles
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def unix_ts(file)
|
11
|
+
File.mtime(file).to_i
|
12
|
+
end
|
13
|
+
|
14
|
+
def strDate_to_unix_timestamp(strDate)
|
15
|
+
Date.strptime(strDate, '%m-%d-%Y').to_time.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate_date_format(strDate)
|
19
|
+
Date.strptime(strDate,'%m-%d-%Y')
|
20
|
+
rescue ArgumentError
|
21
|
+
raise "Invalid date format. Correct format : m-d-y."
|
22
|
+
end
|
23
|
+
|
24
|
+
def date_in_range(date,start_date,end_date)
|
25
|
+
start = strDate_to_unix_timestamp(start_date)
|
26
|
+
finish = strDate_to_unix_timestamp(end_date) + 86399
|
27
|
+
range = start..finish
|
28
|
+
range === date
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/parsefiles.rb
ADDED
data/parsefiles.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'parsefiles/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "parsefiles"
|
8
|
+
spec.version = Parsefiles::VERSION
|
9
|
+
spec.authors = ["Chris Simpson"]
|
10
|
+
spec.email = ["ctsimpson@gmail.com"]
|
11
|
+
spec.description = "Utility for parsing log files"
|
12
|
+
spec.summary = "Parse using regex with support for compressed files"
|
13
|
+
spec.homepage = "http://www.ctsimpson.com"
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.1"
|
24
|
+
spec.add_development_dependency "guard-rspec", "~> 4.2"
|
25
|
+
spec.add_development_dependency "rubyzip"
|
26
|
+
spec.add_dependency "thor"
|
27
|
+
end
|
data/spec/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Parsefiles
|
4
|
+
|
5
|
+
describe FileOps do
|
6
|
+
|
7
|
+
|
8
|
+
let(:filename) { File.join('spec', 'fixtures', 'compressed.tar.gz')}
|
9
|
+
let(:file) {FileOps.new(filename,"test")}
|
10
|
+
|
11
|
+
|
12
|
+
context "when working with files" do
|
13
|
+
|
14
|
+
it "identifies the file type" do
|
15
|
+
expect(file.get_file_type).to eq "gz"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "force UTF-8 encoding" do
|
19
|
+
string = "a\xFAb"
|
20
|
+
expect(file.encode_string(string)).to eq "ab"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "calls parse method name based on file type" do
|
24
|
+
allow(file).to receive(:parse_gz).and_return ''
|
25
|
+
allow(file.parse_file).to receive(:parse_gz)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when checking for matches' do
|
30
|
+
|
31
|
+
it "output the line when pattern is matched" do
|
32
|
+
line = "this do be a test"
|
33
|
+
expect(file.match_line(line)).to eq line
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when parsing zip files' do
|
38
|
+
let(:zip_file) { File.join('spec', 'fixtures', 'compressed.zip')}
|
39
|
+
let(:file) {FileOps.new(zip_file,"ctsimpso$")}
|
40
|
+
|
41
|
+
it "outputs matched content from a compressed zip file" do
|
42
|
+
skip "Zip files not yet implemented"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Parsefiles
|
4
|
+
|
5
|
+
describe Folders do
|
6
|
+
|
7
|
+
context "when testing folder locations" do
|
8
|
+
|
9
|
+
let(:options) {{'start_date' => '06-27-2014', 'end_date' => '06-29-2014'}}
|
10
|
+
|
11
|
+
it "returns the folder location properly when a trailing slash is missing" do
|
12
|
+
test = Folders.new '/var/log', options
|
13
|
+
expect(test.folder).to eq '/var/log/*.{txt,log,gz}'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the folder location properly when their is a trailing slash" do
|
17
|
+
test = Folders.new '/var/log/', options
|
18
|
+
expect(test.folder).to eq '/var/log/*.{txt,log,gz}'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns a single file name when a file name is passed in" do
|
22
|
+
test = Folders.new 'test.log', options
|
23
|
+
expect(test.folder).to eq './test.log'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when testing with start_date and end_date passed in" do
|
28
|
+
|
29
|
+
let(:options) {{'start_date' => '06-27-2014', 'end_date' => '06-29-2014'}}
|
30
|
+
let(:folder) {Folders.new './spec/fixtures/', options}
|
31
|
+
|
32
|
+
it "returns a list of files with date given a parent folder" do
|
33
|
+
output = [["./spec/fixtures/testfile.txt", 1406615852], ["./spec/fixtures/testfile2.txt", 1404000016], ["./spec/fixtures/compressed.tar.gz", 1407343892]]
|
34
|
+
expect(folder.files).to eq output
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns a list of files within a given date range" do
|
38
|
+
output = ['./spec/fixtures/testfile2.txt']
|
39
|
+
files = folder.get_files_in_range
|
40
|
+
expect(files).to eq output
|
41
|
+
end
|
42
|
+
|
43
|
+
it "calculates the start date based on days back attribute" do
|
44
|
+
allow(Date).to receive(:today).and_return(Date.parse('2014-07-20'))
|
45
|
+
expect(folder.calc_start_date 2).to eq '07-18-2014'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns the start date from options if days back option is nil" do
|
49
|
+
expect(folder.get_start_date).to eq '06-27-2014'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when testing with days_back passed in" do
|
55
|
+
|
56
|
+
let(:options) {{"days_back"=>2}}
|
57
|
+
let(:folder) {Folders.new './spec/fixtures/', options}
|
58
|
+
|
59
|
+
it "returns the caculated start date if days_back is set" do
|
60
|
+
allow(folder).to receive(:days_back).and_return("07-14-2014")
|
61
|
+
expect(folder.get_start_date).to eq '07-14-2014'
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'parsefiles/utils'
|
3
|
+
|
4
|
+
module Parsefiles
|
5
|
+
|
6
|
+
describe Utils do
|
7
|
+
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
class Test
|
11
|
+
include Utils
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "converts a Date string to unix timestamp" do
|
16
|
+
expect(Test.strDate_to_unix_timestamp('01-01-2014')).to eq 1388563200
|
17
|
+
end
|
18
|
+
|
19
|
+
it "checks for a valid date format and raises an error if the date format is wrong" do
|
20
|
+
skip "Don't know why this test isn't working"
|
21
|
+
# expect(Test.validate_date_format('01-01d-2014')).to raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it "checks for a valid date format and doesn't return nil for a valid date format" do
|
25
|
+
expect(Test.validate_date_format('01-01-2014')).to eq Date.parse('2014-01-01')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "verifies that a date is within range of the start date and end date" do
|
29
|
+
skip "TODO"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'parsefiles'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
# Run specs in random order to surface order dependencies. If you find an
|
12
|
+
# order dependency and want to debug it, you can fix the order by providing
|
13
|
+
# the seed, which is printed after each run.
|
14
|
+
# --seed 1234
|
15
|
+
config.order = 'random'
|
16
|
+
end
|
data/tasks.TODO
ADDED
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parsefiles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Simpson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubyzip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Utility for parsing log files
|
98
|
+
email:
|
99
|
+
- ctsimpson@gmail.com
|
100
|
+
executables:
|
101
|
+
- parsefiles
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".DS_Store"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- Gemfile
|
109
|
+
- Guardfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/parsefiles
|
114
|
+
- lib/.DS_Store
|
115
|
+
- lib/cli.rb
|
116
|
+
- lib/parsefiles.rb
|
117
|
+
- lib/parsefiles/file_ops.rb
|
118
|
+
- lib/parsefiles/folders.rb
|
119
|
+
- lib/parsefiles/parse.rb
|
120
|
+
- lib/parsefiles/utils.rb
|
121
|
+
- lib/parsefiles/version.rb
|
122
|
+
- parsefiles.gemspec
|
123
|
+
- spec/.DS_Store
|
124
|
+
- spec/fixtures/compressed.tar.gz
|
125
|
+
- spec/fixtures/compressed.zip
|
126
|
+
- spec/fixtures/testfile.txt
|
127
|
+
- spec/fixtures/testfile2.txt
|
128
|
+
- spec/lib/cli_spec.rb
|
129
|
+
- spec/lib/parsefiles/file_spec.rb
|
130
|
+
- spec/lib/parsefiles/folders_spec.rb
|
131
|
+
- spec/lib/parsefiles/utils_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- tasks.TODO
|
134
|
+
homepage: http://www.ctsimpson.com
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.2.2
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Parse using regex with support for compressed files
|
158
|
+
test_files:
|
159
|
+
- spec/.DS_Store
|
160
|
+
- spec/fixtures/compressed.tar.gz
|
161
|
+
- spec/fixtures/compressed.zip
|
162
|
+
- spec/fixtures/testfile.txt
|
163
|
+
- spec/fixtures/testfile2.txt
|
164
|
+
- spec/lib/cli_spec.rb
|
165
|
+
- spec/lib/parsefiles/file_spec.rb
|
166
|
+
- spec/lib/parsefiles/folders_spec.rb
|
167
|
+
- spec/lib/parsefiles/utils_spec.rb
|
168
|
+
- spec/spec_helper.rb
|