splitter 0.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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in splitter.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rspec', '~> 2.0'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ end
data/Guardfile ADDED
@@ -0,0 +1,25 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
14
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
15
+ watch('spec/spec_helper.rb') { "spec" }
16
+ watch('config/routes.rb') { "spec/routing" }
17
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
18
+ # Capybara request specs
19
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
20
+ end
21
+
22
+ guard 'bundler' do
23
+ watch('Gemfile')
24
+ watch(/^.+\.gemspec/)
25
+ end
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Splitter
2
+ VERSION = "0.0.1"
3
+ end
data/lib/splitter.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "splitter/version"
2
+
3
+ module Splitter
4
+ class << self
5
+ DEFAULT_BATCH_SIZE = 100
6
+
7
+ def split(filename, options)
8
+ start_wrapper = options[:start_wrapper] || (raise ArgumentError, "A starting wrapper tag (:start_wrapper) must be provided.")
9
+ end_wrapper = options[:end_wrapper] || (raise ArgumentError, "An ending wrapper tag (:end_wrapper) must be provided.")
10
+ splitter = options[:splitter] || (raise ArgumentError, "A splitter tag (:splitter) must be provided.")
11
+ batch_size = options[:batch_size] || DEFAULT_BATCH_SIZE
12
+
13
+ s = ""
14
+ count = 0
15
+ File.open(filename) do |f|
16
+ while(line = f.read(1024))
17
+ match = false
18
+
19
+ while(i = line.index(splitter))
20
+ match = true
21
+ count += 1
22
+ s << "#{line[0...i]}#{splitter}"
23
+
24
+ if count > 0 && count % batch_size == 0
25
+ s << end_wrapper
26
+ yield s
27
+ s.clear
28
+ s << start_wrapper
29
+ count = 0
30
+ end
31
+
32
+ line = line[(i+splitter.size)..-1]
33
+ end
34
+
35
+ s << line unless line.empty?
36
+ end
37
+ end
38
+
39
+ yield s unless s.empty? || s =~ /#{start_wrapper}\s*#{end_wrapper}/
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Splitter do
4
+ pending "Need to test everything"
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler.require :default, :test
3
+ require 'splitter'
4
+
5
+ RSpec.configure do |config|
6
+ config.before do
7
+ end
8
+ end
data/splitter.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "splitter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "splitter"
7
+ s.version = Splitter::VERSION
8
+ s.authors = ["Jon Hinson"]
9
+ s.email = ["hinson.jonathan@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Split xml files into smaller pieces.}
12
+ s.description = %q{Split xml files into smaller pieces.}
13
+
14
+ s.rubyforge_project = "splitter"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: splitter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jon Hinson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-26 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Split xml files into smaller pieces.
18
+ email:
19
+ - hinson.jonathan@gmail.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - Guardfile
30
+ - Rakefile
31
+ - lib/splitter.rb
32
+ - lib/splitter/version.rb
33
+ - spec/lib/splitter_spec.rb
34
+ - spec/spec_helper.rb
35
+ - splitter.gemspec
36
+ has_rdoc: true
37
+ homepage: ""
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project: splitter
60
+ rubygems_version: 1.6.2
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Split xml files into smaller pieces.
64
+ test_files:
65
+ - spec/lib/splitter_spec.rb
66
+ - spec/spec_helper.rb