file_manipulator 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 5b88660cb573545850174c3d53c1c4d90348c1c1
4
- data.tar.gz: f4e06e329d7da75e1b0ad8d2ff8052399bdae08c
3
+ metadata.gz: 937bffc24fae30311ce2bb2841b5a7ae835151e0
4
+ data.tar.gz: d357a2b0050d6ccef87e28f42765dd7582b5fef0
5
5
  SHA512:
6
- metadata.gz: 63ed38aac04d7ade1aab829a6ad68a54008e42afd1eb31693b69aeaaf9100b76529881840790ce9bde60172947b5a7bbd02ae1a6aee569b6f473b5ba2431d385
7
- data.tar.gz: 9072b431e401fbfcfa01329ab6b37da62bbe5ad129f39759ddb7f2a34eb960de1d8a5d10d3079c9a2c8f2fa973fd6fabc0bfb88d2efcae650fbc1b474dbf255e
6
+ metadata.gz: 7cc4e6b0b3df299885000a6776517315f2d85c5c2e514848cdf96711a9a40c6d464d5501eed5555ef1a13186a09662947e4089bcfc0779c10e8d3157bd5512ed
7
+ data.tar.gz: 5eb194916d6735dd0ee6490842eee16bace180153bdb5efe903d4112b900bd5211d4c49daa5edfb1c72d58313382ec242499aea1fbc0134028697d3dd01e49d0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- file_manipulator (0.0.1)
4
+ file_manipulator (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- irb(main):001:0> require 'file_manipulator'
27
- => true
28
- irb(main):002:0> FileManipulator.split('Gemfile', 'tmp', 1)
29
- => nil
30
- irb(main):003:0> Dir.entries('tmp')
31
- => [".", "..", "Gemfile_0000", "Gemfile_0001", "Gemfile_0002", "Gemfile_0003"]
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
@@ -0,0 +1,5 @@
1
+ module FileManipulator
2
+ class Configuration
3
+ attr_accessor :prefix, :file_name, :output_directory, :size
4
+ end
5
+ end
@@ -1,11 +1,9 @@
1
1
  module FileManipulator
2
2
  class Splitter
3
- attr_accessor :file_name, :output_directory, :size
3
+ attr_reader :config
4
4
 
5
- def initialize(file_name, output_directory, size = 10_485_760)
6
- @file_name = file_name
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
@@ -1,3 +1,3 @@
1
1
  module FileManipulator
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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(file_name, output_directory, size)
8
- Splitter.new(file_name, output_directory, size).run
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.1
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-10 00:00:00.000000000 Z
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