file-cleaner 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmM0MGVkYzVhOWMxNzJjYzlkYWE0NmNhNmE1MzUxYWZmNzYyZDNjYw==
5
+ data.tar.gz: !binary |-
6
+ N2Y4MzU3YmYxOWViODY0YjM3ODM2OTRhMmM0Y2QyYWJhODU0N2NjZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NjQ1NjNiYjlkNDhiNjgxM2Q5YmFkMzU3MzVkMjYyNWNiZTRhMTk4Y2U4ZjE1
10
+ YjBjMDZjYzM2OGFkOGRjNDkxY2IzNTE1NTk3YzM2YmI4YjIwYmQ5ZGZlZDdj
11
+ ZWYwMmNiZmRjNGE2MmYyZWQwMDVlMDg0MDY4YzA3MmUxOTYzMzk=
12
+ data.tar.gz: !binary |-
13
+ NGI3NzI1Yjg4NGE5NTAzNTY4MDBiM2ZjNTc0ZTcyOTQzMzRiOTgzNWRlYmU2
14
+ MmU0Y2Y5MTkzMWNjMjkxZmQyZTY2NjFhZGVhYTNkMGQ1MmM0ZTEwYzc5ZmUz
15
+ YzMxYTk1NWFkZDEyMTg2OWIxMmQ0Zjg0YzVhMzM1OTEzZTg3ZjI=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in file_cleaner.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Arturo Pie
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,39 @@
1
+ # FileCleaner
2
+
3
+ This library filters lines or group of lines from a file by using regular expressions and ranges.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'file_cleaner'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install file_cleaner
18
+
19
+ ## Usage
20
+
21
+ To remove all lines of file `/path/to/file` that match regular expression `/Remove me/`:
22
+
23
+ require 'file_cleaner'
24
+ FileCleaner.remove(pattern: /Remove me/,
25
+ file_path: /path/to/file)
26
+
27
+ To remove lines that match regular expression, a line above and a line bellow:
28
+
29
+ FileCleaner.remove(pattern: /Remove me/,
30
+ file_path: /path/to/file,
31
+ range: -1..1)
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'file_cleaner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "file-cleaner"
8
+ spec.version = FileCleaner::VERSION
9
+ spec.authors = ["Arturo Pie"]
10
+ spec.email = ["arturotd08@yahoo.ca"]
11
+ spec.description = %q{Filters out lines of files}
12
+ spec.summary = %q{This library filters lines or group of lines from a file by using regular expressions and ranges.}
13
+ spec.homepage = "https://github.com/arturopie/file-cleaner"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec", "~> 2.14.1"
23
+ end
@@ -0,0 +1,27 @@
1
+ require "file_cleaner/version"
2
+
3
+ module FileCleaner
4
+ def self.remove args
5
+ file_path = args[:file_path]
6
+ pattern = args[:pattern]
7
+ range = args.fetch(:range, 0..0)
8
+
9
+ lines = []
10
+ File.open(file_path, 'r') do |f|
11
+ lines = f.readlines
12
+ end
13
+
14
+ match_indexes = lines.each_with_index.select { |line,_| line =~ pattern }.map { |_, index| index }
15
+ match_indexes.each do |match_index|
16
+ moved_range = Range.new(range.begin + match_index, range.end + match_index, range.exclude_end?)
17
+ lines.fill(nil, moved_range)
18
+ end
19
+ result = lines.compact
20
+
21
+ File.open(file_path, 'w+') do |f|
22
+ result.each do |line|
23
+ f.write line
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module FileCleaner
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,54 @@
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+ require 'file_cleaner'
4
+
5
+ describe FileCleaner do
6
+
7
+ describe '.remove' do
8
+ before :each do
9
+ @file_path = 'spec/tmp/a_file'
10
+ File.open(@file_path, 'w+') do |f|
11
+ f.write "line 1\n"
12
+ f.write "Remove me\n"
13
+ f.write "line 2\n"
14
+ f.write "line 3\n"
15
+ end
16
+ end
17
+
18
+ context 'removing using pattern without passing a range' do
19
+ before do
20
+ FileCleaner.remove(pattern: /Remove me/,
21
+ file_path: @file_path)
22
+ end
23
+ subject { result }
24
+ it { should eq(["line 1\n", "line 2\n", "line 3\n"]) }
25
+ end
26
+
27
+ context 'removing using pattern and range' do
28
+ before do
29
+ FileCleaner.remove(pattern: /Remove me/,
30
+ file_path: @file_path,
31
+ range: -1..1)
32
+ end
33
+ subject { result }
34
+ it { should eq(["line 3\n"])}
35
+ end
36
+
37
+ context 'removing using pattern and exclusive range' do
38
+ before do
39
+ FileCleaner.remove(pattern: /Remove me/,
40
+ file_path: @file_path,
41
+ range: -1...2)
42
+ end
43
+ subject { result }
44
+ it { should eq(["line 3\n"])}
45
+ end
46
+
47
+ def result
48
+ f = File.open(@file_path, 'r')
49
+ lines = f.readlines
50
+ f.close
51
+ lines
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file-cleaner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arturo Pie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-25 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.14.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.14.1
55
+ description: Filters out lines of files
56
+ email:
57
+ - arturotd08@yahoo.ca
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - .ruby-version
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - file_cleaner.gemspec
70
+ - lib/file_cleaner.rb
71
+ - lib/file_cleaner/version.rb
72
+ - spec/file_cleaner_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: https://github.com/arturopie/file-cleaner
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.1.11
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: This library filters lines or group of lines from a file by using regular
98
+ expressions and ranges.
99
+ test_files:
100
+ - spec/file_cleaner_spec.rb
101
+ - spec/spec_helper.rb