file_manipulator 0.0.1 → 0.0.2
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/Gemfile.lock +1 -1
- data/README.md +15 -9
- data/lib/file_manipulator/configuration.rb +5 -0
- data/lib/file_manipulator/splitter.rb +13 -7
- data/lib/file_manipulator/version.rb +1 -1
- data/lib/file_manipulator.rb +16 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 937bffc24fae30311ce2bb2841b5a7ae835151e0
|
4
|
+
data.tar.gz: d357a2b0050d6ccef87e28f42765dd7582b5fef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cc4e6b0b3df299885000a6776517315f2d85c5c2e514848cdf96711a9a40c6d464d5501eed5555ef1a13186a09662947e4089bcfc0779c10e8d3157bd5512ed
|
7
|
+
data.tar.gz: 5eb194916d6735dd0ee6490842eee16bace180153bdb5efe903d4112b900bd5211d4c49daa5edfb1c72d58313382ec242499aea1fbc0134028697d3dd01e49d0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# FileManipulator
|
2
2
|
|
3
|
-
TODO: Delete this and the text above, and describe your gem
|
4
|
-
|
5
3
|
`FileManipulator` can split a text formatted file and merge them to one file (merge is TODO now).
|
6
4
|
|
7
5
|
## Installation
|
@@ -22,13 +20,21 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'file_manipulator'
|
26
|
+
|
27
|
+
FileManipulator.configure do |config|
|
28
|
+
config.prefix = 'file_manipulator'
|
29
|
+
config.file_name = 'Gemfile.lock'
|
30
|
+
config.output_directory = 'tmp'
|
31
|
+
config.size = 1
|
32
|
+
end
|
33
|
+
|
34
|
+
FileManipulator.split
|
35
|
+
|
36
|
+
Dir.entries('tmp')
|
37
|
+
#=> [".", "..", "file_manipulator_Gemfile_0000", "file_manipulator_Gemfile_0001", "file_manipulator_Gemfile_0002", "file_manipulator_Gemfile_0003"]
|
32
38
|
```
|
33
39
|
|
34
40
|
## Development
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module FileManipulator
|
2
2
|
class Splitter
|
3
|
-
|
3
|
+
attr_reader :config
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
@output_directory = output_directory
|
8
|
-
@size = size
|
5
|
+
def initialize(config = FileManipulator.configuration)
|
6
|
+
@config = config
|
9
7
|
end
|
10
8
|
|
11
9
|
def run
|
@@ -13,7 +11,7 @@ module FileManipulator
|
|
13
11
|
|
14
12
|
File.open(file_name, 'r') do |input|
|
15
13
|
until input.eof?
|
16
|
-
File.open(File.join(output_directory, output_file_name(index)), 'w') do |output|
|
14
|
+
File.open(File.join(config.output_directory, output_file_name(index)), 'w') do |output|
|
17
15
|
line = ""
|
18
16
|
|
19
17
|
while output.size <= (size - line.length) && !input.eof?
|
@@ -37,14 +35,22 @@ module FileManipulator
|
|
37
35
|
File.extname(file_name).delete('.')
|
38
36
|
end
|
39
37
|
|
38
|
+
def file_name
|
39
|
+
config.file_name
|
40
|
+
end
|
41
|
+
|
40
42
|
def number_of_digits
|
41
43
|
@number_of_digits ||= Math.log10(File.size(file_name).to_f / size).ceil + 1
|
42
44
|
end
|
43
45
|
|
44
46
|
def output_file_name(index)
|
45
47
|
output_file_basename = sprintf("#{basename}_%0#{number_of_digits}d", index)
|
46
|
-
|
48
|
+
output_file_basename = "#{config.prefix}_#{output_file_basename}" unless config.prefix == ''
|
47
49
|
extname == '' ? output_file_basename : "#{output_file_basename}.#{extname}"
|
48
50
|
end
|
51
|
+
|
52
|
+
def size
|
53
|
+
config.size
|
54
|
+
end
|
49
55
|
end
|
50
56
|
end
|
data/lib/file_manipulator.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
require "file_manipulator/splitter"
|
2
|
+
require "file_manipulator/configuration"
|
2
3
|
require "file_manipulator/version"
|
3
4
|
|
4
5
|
module FileManipulator
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.reset
|
16
|
+
@configuration = Configuration.new
|
17
|
+
end
|
18
|
+
|
5
19
|
module_function
|
6
20
|
|
7
|
-
def split
|
8
|
-
Splitter.new
|
21
|
+
def split
|
22
|
+
Splitter.new.run
|
9
23
|
end
|
10
24
|
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.0.2
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- exe/file_manipulator
|
105
105
|
- file_manipulator.gemspec
|
106
106
|
- lib/file_manipulator.rb
|
107
|
+
- lib/file_manipulator/configuration.rb
|
107
108
|
- lib/file_manipulator/splitter.rb
|
108
109
|
- lib/file_manipulator/version.rb
|
109
110
|
- tmp/.keep
|