dry-file 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '05033942756985182b36d42efab7fab3a5889ef3c962b43f5f23278e0255715e'
4
- data.tar.gz: 3db77fccd38ea90edeca92d15b398415e5e76c90b58672516190caefc7cf5557
3
+ metadata.gz: 8f0c30f41095a9db669ec7d0c0c2e37b8240ea30516aa1fed27704bdd94bceb4
4
+ data.tar.gz: 4b47bac06e808deaa5a60bd7e972d8cb46b71d000f186205b3a687dfff4eaedf
5
5
  SHA512:
6
- metadata.gz: 7abcbe9c8115af222732a346b204318292b670c1e293b19184e12308bd893f2ccd51c12c46a025f28072a99f5a0420ccbbd38845564589bfdc51037b47b30f24
7
- data.tar.gz: 8cb92f269c12dc0bb74b20be903e8655257ddfd8d5549281e617bf4968d8847eea357ac7bc72aecf772de18308edd56e768da3b6a17ce64cc565692c2826284f
6
+ metadata.gz: a60d28399e5dbeca9f75b7adaa6ad61b9f33cd65094fc61d25ae16e24dcf2adcbd6935de0331ad75d3044469b25fb956d75aef51d5486639f0e2ef5831e5c9ad
7
+ data.tar.gz: 1d2f01e718768cc1b73a833a5dabd34525abe7f2bba666c28da3072d2cb53af8f2ae727402011daea92dad6ed0936695e3fcde66fb1a608fe35633b4dce350db
data/README.md CHANGED
@@ -1,35 +1,22 @@
1
- # Dry::File
1
+ Purpose:
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dry/file`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Remove duplicate URLs from a file, where the URLs only differ by N characters
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Usage:
6
6
 
7
- ## Installation
7
+ # With pipe
8
+ cat <file> | dry <N>
8
9
 
9
- Add this line to your application's Gemfile:
10
+ # With file
11
+ dry <N> <file> [options]
10
12
 
11
- ```ruby
12
- gem 'dry-file'
13
- ```
13
+ Example:
14
14
 
15
- And then execute:
15
+ # Read from a pipe and print to stdout
16
+ cat file | dry 50
16
17
 
17
- $ bundle install
18
+ # Which is the same as
19
+ dry 50 file
18
20
 
19
- Or install it yourself as:
20
-
21
- $ gem install dry-file
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dry-file.
21
+ # Replace file in-place
22
+ dry 40 $domain/scan/gf/xss.txt -i
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module File
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
data/lib/dry-file.rb CHANGED
@@ -9,30 +9,34 @@ module Dry
9
9
  # === Usage
10
10
  # dry 40 test/data/sqli.txt
11
11
  # === Params
12
- # max_chars: minimum number of different characters to keep a line
13
- # file: input file
14
- def run(max_chars, file)
12
+ # max_chars: minimum number of different characters to keep a line.
13
+ # file: input file.
14
+ # options: '-i' replace file in-place.
15
+ def run(max_chars, file=nil, *options)
15
16
  max_chars = max_chars.to_i
16
17
  previous_line = ''
17
- file_out = Tempfile.new(File.basename(file))
18
+ new_lines = ''
19
+ ARGV.clear
18
20
 
19
- File.open(file).each_line do |l|
21
+ lines = file.nil? ? ARGF.read : File.open(file)
22
+
23
+ lines.each_line do |l|
20
24
  # We compare the line size as well as the line similarity. We could have
21
25
  # different treshold values for each of these comparisons (eg use
22
26
  # +max_chars+ for the size comparison and +max_diff_chars+ for the
23
27
  # similarity comparison, but i think using +max_chars+ for both
24
28
  # comparisons is also OK, the results seem pretty good.
25
29
  if (previous_line.size - l.size).abs > max_chars || diff_size(previous_line, l) > max_chars
26
- file_out.write l
30
+ new_lines << l
27
31
  previous_line = l
28
32
  end
29
33
  end
30
- file_out.close
31
- FileUtils.mv(file_out.path, File.join(File.dirname(file), "dry-#{File.basename(file)}"))
34
+
35
+ options.include?('-i') ? File.write(file, new_lines) : puts(new_lines)
32
36
  end
33
37
 
34
38
  # Returns the number of differing characters between two lines.
35
39
  def diff_size(line_1, line_2)
36
- line1.chars.each_with_index.filter_map{|c,i| line1[i] != line2[i]}.size
40
+ line_1.chars.each_with_index.filter_map{|c,i| line_1[i] != line_2[i]}.size
37
41
  end
38
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Romero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-18 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Removes almost identical lines based on a similarity parameter.
14
14
  email: