file_manipulator 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/file_manipulator.gemspec +1 -0
- data/lib/file_manipulator/configuration.rb +1 -1
- data/lib/file_manipulator/merger.rb +27 -0
- data/lib/file_manipulator/splitter.rb +3 -7
- data/lib/file_manipulator/version.rb +1 -1
- data/lib/file_manipulator.rb +14 -11
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dca692b9e18d8ae123236c46bc35b21a9ad7be7
|
4
|
+
data.tar.gz: 588ad83c8169803af73ba8e0cba5b7fa68218067
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b9e4cc0e29a567614333591868f92ef6ed68a8abf61d00b4f315733c3dcec220159c4a7d8671cee264cb30f49e1fb0ce52d84d8d69860d16d44f964df7d268a
|
7
|
+
data.tar.gz: 84ddab6b8b674052907087c478a2b04f3e231c82bc87a5e9320c1a4cf15869c4ad46fba20e8e5ff63d76e7aa25946ca0d818974dbc270563d4effc487e94feef
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# FileManipulator
|
2
2
|
|
3
|
-
`FileManipulator` can split a text formatted file and merge them to one file
|
3
|
+
`FileManipulator` can split a text formatted file and merge them to one file.
|
4
4
|
|
5
5
|
<!-- http://shields.io/ -->
|
6
6
|
[![Build Status](https://travis-ci.org/gipcompany/file_manipulator.svg?branch=master_issue_3)](https://travis-ci.org/gipcompany/file_manipulator)
|
@@ -28,15 +28,15 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
|
32
31
|
```ruby
|
33
32
|
require 'file_manipulator'
|
34
33
|
|
35
34
|
FileManipulator.configure do |config|
|
36
35
|
config.prefix = 'file_manipulator'
|
37
36
|
config.file_name = 'Gemfile'
|
38
|
-
config.
|
39
|
-
config.
|
37
|
+
config.split_files_directory = 'tmp'
|
38
|
+
config.merged_file_directory = 'tmp'
|
39
|
+
config.size = 10
|
40
40
|
end
|
41
41
|
|
42
42
|
FileManipulator.split
|
data/file_manipulator.gemspec
CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_development_dependency "pry", '~> 0.10.4'
|
28
28
|
spec.add_development_dependency "pry-byebug", '~> 3.4.0'
|
29
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
29
30
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FileManipulator
|
2
|
+
class Merger
|
3
|
+
attr_reader :config
|
4
|
+
|
5
|
+
def initialize(config = FileManipulator.configuration)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
string_io = StringIO.new
|
11
|
+
|
12
|
+
Dir.glob("#{config.split_files_directory}/#{config.prefix}_*").sort.each do |file|
|
13
|
+
string_io.puts File.read(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
File.write(merged_file, string_io.string)
|
17
|
+
end
|
18
|
+
|
19
|
+
def merged_file
|
20
|
+
sample_split_file = Dir.glob("#{config.split_files_directory}/#{config.prefix}_*").first
|
21
|
+
basename = File.basename(sample_split_file)
|
22
|
+
extname = File.extname(sample_split_file)
|
23
|
+
basename = basename.sub(/^#{config.prefix}_/, '').sub(/#{extname}$/, '').sub(/_\d*$/, '')
|
24
|
+
File.join(config.merged_file_directory, "#{basename}#{extname}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -11,10 +11,10 @@ module FileManipulator
|
|
11
11
|
|
12
12
|
File.open(file_name, 'r') do |input|
|
13
13
|
until input.eof?
|
14
|
-
File.open(File.join(config.
|
14
|
+
File.open(File.join(config.split_files_directory, output_file_name(index)), 'w') do |output|
|
15
15
|
line = ""
|
16
16
|
|
17
|
-
while output.size <= (size - line.length) && !input.eof?
|
17
|
+
while output.size <= (config.size - line.length) && !input.eof?
|
18
18
|
line = input.readline
|
19
19
|
output << line
|
20
20
|
end
|
@@ -40,7 +40,7 @@ module FileManipulator
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def number_of_digits
|
43
|
-
@number_of_digits ||= Math.log10(File.size(file_name).to_f / size).ceil + 1
|
43
|
+
@number_of_digits ||= Math.log10(File.size(file_name).to_f / config.size).ceil + 1
|
44
44
|
end
|
45
45
|
|
46
46
|
def output_file_name(index)
|
@@ -48,9 +48,5 @@ module FileManipulator
|
|
48
48
|
output_file_basename = "#{config.prefix}_#{output_file_basename}" unless config.prefix == ''
|
49
49
|
extname == '' ? output_file_basename : "#{output_file_basename}.#{extname}"
|
50
50
|
end
|
51
|
-
|
52
|
-
def size
|
53
|
-
config.size
|
54
|
-
end
|
55
51
|
end
|
56
52
|
end
|
data/lib/file_manipulator.rb
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
require "file_manipulator/splitter"
|
2
|
+
require "file_manipulator/merger"
|
2
3
|
require "file_manipulator/configuration"
|
3
4
|
require "file_manipulator/version"
|
4
5
|
|
5
6
|
module FileManipulator
|
6
7
|
class << self
|
7
8
|
attr_accessor :configuration
|
8
|
-
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def configure
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def reset
|
16
|
+
@configuration = Configuration.new
|
17
|
+
end
|
18
18
|
|
19
|
-
|
19
|
+
def split
|
20
|
+
Splitter.new.run
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
def merge
|
24
|
+
Merger.new.run
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_manipulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atsushi Ishida
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.4.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Manipulate (Split/Merge) Files
|
84
98
|
email:
|
85
99
|
- gipcompany@gmail.com
|
@@ -106,6 +120,7 @@ files:
|
|
106
120
|
- file_manipulator.gemspec
|
107
121
|
- lib/file_manipulator.rb
|
108
122
|
- lib/file_manipulator/configuration.rb
|
123
|
+
- lib/file_manipulator/merger.rb
|
109
124
|
- lib/file_manipulator/splitter.rb
|
110
125
|
- lib/file_manipulator/version.rb
|
111
126
|
- tmp/.keep
|