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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ae1661bf396027cce8b94f19cc7f1587afd530f
4
- data.tar.gz: 8ff59632648903b6c38f005bacf6316360447649
3
+ metadata.gz: 1cd1426cf5dffc7f1401d486527eb3bf1bf0102f
4
+ data.tar.gz: 5346b33dcf65c728e7b5c29ee9cc6312eb9c9cf2
5
5
  SHA512:
6
- metadata.gz: 938bbc2c32925bf02f763492959b8b655c2ab24d8689fa06ad22d91160abffd50949ea4fb363bd682c03a42377eaab6cde512f3ee9476cfe1905fc5db12ada0c
7
- data.tar.gz: a612a7742c5608df4d1a9f6cb936853e2eddd07b738a494ee687b9c37349bcd9b18069089f374513ed65003299c066f1dd4bafd29f5fb613aa751c3f0a1cf44c
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
@@ -2,4 +2,5 @@
2
2
 
3
3
  require 'partline'
4
4
 
5
- Partline::Partline.new
5
+ start = Partline::Partline.new
6
+ start.get_input
@@ -1,3 +1,3 @@
1
1
  module Partline
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/partline.rb CHANGED
@@ -1,33 +1,41 @@
1
- require 'partline/version'
2
- require 'tempfile'
1
+ require "partline/version"
2
+ require "tempfile"
3
3
 
4
4
  module Partline
5
5
  class Partline
6
6
  def initialize
7
- if ARGV.length < 2
8
- puts "Please enter both a file name and character(s) to part on"
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 = Tempfile.new('tmp')
11
- @input = IO.read(ARGV[0])
13
+ @temp_file = Tempfile.new('tmp')
14
+ @input_file = i[0]
15
+ @delimiter = i[1]
12
16
 
13
- self.input_to_tempfile
14
- self.remove_line
17
+ input_to_tempfile
15
18
  end
16
19
  end
17
20
 
18
21
  def input_to_tempfile
19
- @temp_file << @input
22
+ if File.exist?(@input_file)
23
+ @temp_file << IO.read(@input_file)
24
+ @temp_file.rewind
20
25
 
21
- @temp_file.rewind
26
+ part_line
27
+ else
28
+ input_error("File does not exist. ")
29
+ end
22
30
  end
23
31
 
24
- def remove_line
25
- File.delete(ARGV[0])
26
- File.open(ARGV[0], "a") do |out|
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(ARGV[1])
29
- part_line = current_line.partition(ARGV[1]).first.strip
30
- out.puts part_line unless part_line.empty?
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.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-06 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler