file_manipulator 0.0.4 → 0.1.0

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: 72afa4ea70ad0b5f91c8576a45e9db415345ca70
4
- data.tar.gz: 9af4a2d596c340ebe51bcf675e5f6300c2176d74
3
+ metadata.gz: 3dca692b9e18d8ae123236c46bc35b21a9ad7be7
4
+ data.tar.gz: 588ad83c8169803af73ba8e0cba5b7fa68218067
5
5
  SHA512:
6
- metadata.gz: 7bf25e50c69d1dbb2dca8d4a0e03c8b5d204844d64a587ee65fdd9ce87f994de881ac10f626eb84c2c5b148af7b876271f907418b61fc372f534adb20e1d93b6
7
- data.tar.gz: 23afca8f553c818abfa4620bf77428b66b47f938b8dcaadd0f025a35a915d557c385cd78ce27a8b359397dda93318c7b5f681c538c9848ffa47e4e7ec9a54ee6
6
+ metadata.gz: 7b9e4cc0e29a567614333591868f92ef6ed68a8abf61d00b4f315733c3dcec220159c4a7d8671cee264cb30f49e1fb0ce52d84d8d69860d16d44f964df7d268a
7
+ data.tar.gz: 84ddab6b8b674052907087c478a2b04f3e231c82bc87a5e9320c1a4cf15869c4ad46fba20e8e5ff63d76e7aa25946ca0d818974dbc270563d4effc487e94feef
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in file_manipulator.gemspec
4
4
  gemspec
5
-
6
- gem 'codeclimate-test-reporter', group: :test, require: nil
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- file_manipulator (0.0.4)
4
+ file_manipulator (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 (merge is TODO (#4) now).
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.output_directory = 'tmp'
39
- config.size = 1
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module FileManipulator
2
2
  class Configuration
3
- attr_accessor :prefix, :file_name, :output_directory, :size
3
+ attr_accessor :prefix, :file_name, :split_files_directory, :merged_file_directory, :size
4
4
  end
5
5
  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.output_directory, output_file_name(index)), 'w') do |output|
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
@@ -1,3 +1,3 @@
1
1
  module FileManipulator
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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
- def self.configure
11
- @configuration ||= Configuration.new
12
- yield(configuration)
13
- end
10
+ def configure
11
+ @configuration ||= Configuration.new
12
+ yield(configuration)
13
+ end
14
14
 
15
- def self.reset
16
- @configuration = Configuration.new
17
- end
15
+ def reset
16
+ @configuration = Configuration.new
17
+ end
18
18
 
19
- module_function
19
+ def split
20
+ Splitter.new.run
21
+ end
20
22
 
21
- def split
22
- Splitter.new.run
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
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-18 00:00:00.000000000 Z
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