partline 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/bin/partline +2 -1
- data/lib/partline/version.rb +1 -1
- data/lib/partline.rb +35 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cd1426cf5dffc7f1401d486527eb3bf1bf0102f
|
4
|
+
data.tar.gz: 5346b33dcf65c728e7b5c29ee9cc6312eb9c9cf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 664f7338e6835c51f878eb98e2a9e9d1ac7267c9b32b03747fcef2e48bf444970dd342d60678629fe966e7f24acea1b7b20de05edb64faacc4526f464201a6fb
|
7
|
+
data.tar.gz: ee970a704708e2d437009e3481b182f99877e9c7f21ab330c437d7c6586751e0106ceeac48c99643a5194883e65b60df51e0e7e7e8378022589ec2ddc99f4d50
|
data/README.md
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
I originally made this to remove comments from an input file. It could probably
|
4
4
|
remove anything passed to it but have not tested it.
|
5
5
|
|
6
|
-
This was made fairly quickly, it may not be following best practices
|
6
|
+
This was made fairly quickly, it may not be following best practices and may
|
7
|
+
have some bugs.
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
data/bin/partline
CHANGED
data/lib/partline/version.rb
CHANGED
data/lib/partline.rb
CHANGED
@@ -1,33 +1,41 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "partline/version"
|
2
|
+
require "tempfile"
|
3
3
|
|
4
4
|
module Partline
|
5
5
|
class Partline
|
6
6
|
def initialize
|
7
|
-
|
8
|
-
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_input(i = [ARGV[0], ARGV[1]])
|
10
|
+
if i[1].nil?
|
11
|
+
input_error("Not enough arguments or delimiter is not surrounded by quotes. ")
|
9
12
|
else
|
10
|
-
@temp_file
|
11
|
-
@
|
13
|
+
@temp_file = Tempfile.new('tmp')
|
14
|
+
@input_file = i[0]
|
15
|
+
@delimiter = i[1]
|
12
16
|
|
13
|
-
|
14
|
-
self.remove_line
|
17
|
+
input_to_tempfile
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def input_to_tempfile
|
19
|
-
|
22
|
+
if File.exist?(@input_file)
|
23
|
+
@temp_file << IO.read(@input_file)
|
24
|
+
@temp_file.rewind
|
20
25
|
|
21
|
-
|
26
|
+
part_line
|
27
|
+
else
|
28
|
+
input_error("File does not exist. ")
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
|
-
def
|
25
|
-
File.delete(
|
26
|
-
File.open(
|
32
|
+
def part_line
|
33
|
+
File.delete(@input_file)
|
34
|
+
File.open(@input_file, "a") do |out|
|
27
35
|
@temp_file.read.each_line do |current_line|
|
28
|
-
if current_line.match(
|
29
|
-
|
30
|
-
out.puts
|
36
|
+
if current_line.match(@delimiter)
|
37
|
+
output_line = current_line.partition(@delimiter).first.strip
|
38
|
+
out.puts output_line unless output_line.empty?
|
31
39
|
else
|
32
40
|
out.puts(current_line)
|
33
41
|
end
|
@@ -35,5 +43,16 @@ module Partline
|
|
35
43
|
end
|
36
44
|
puts "partline has finished"
|
37
45
|
end
|
46
|
+
|
47
|
+
def input_error(p = "")
|
48
|
+
begin
|
49
|
+
error = lambda do |e|
|
50
|
+
puts e + "Please enter both a valid file name and character(s) to part on"
|
51
|
+
end
|
52
|
+
raise
|
53
|
+
rescue
|
54
|
+
error.call(p)
|
55
|
+
end
|
56
|
+
end
|
38
57
|
end
|
39
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Wren
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|