splitter 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.
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- .DS_Store
5
+ .DS_Store
6
+ .rvmrc
@@ -8,16 +8,14 @@ module Splitter
8
8
  start_wrapper = options[:start_wrapper] || (raise ArgumentError, "A starting wrapper tag (:start_wrapper) must be provided.")
9
9
  end_wrapper = options[:end_wrapper] || (raise ArgumentError, "An ending wrapper tag (:end_wrapper) must be provided.")
10
10
  splitter = options[:splitter] || (raise ArgumentError, "A splitter tag (:splitter) must be provided.")
11
+ splitter = "</#{splitter}>" unless splitter =~ /\<\/.+\>/
11
12
  batch_size = options[:batch_size] || DEFAULT_BATCH_SIZE
12
13
 
13
14
  s = ""
14
15
  count = 0
15
16
  File.open(filename) do |f|
16
17
  while(line = f.read(1024))
17
- match = false
18
-
19
18
  while(i = line.index(splitter))
20
- match = true
21
19
  count += 1
22
20
  s << "#{line[0...i]}#{splitter}"
23
21
 
@@ -1,3 +1,3 @@
1
1
  module Splitter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
File without changes
@@ -1,5 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Splitter do
4
- pending "Need to test everything"
4
+ before(:all) do
5
+ @default_options = {
6
+ :start_wrapper => "<Foos>",
7
+ :end_wrapper => "</Foos>",
8
+ :splitter => "</Foo>"
9
+ }
10
+ end
11
+ context "parse" do
12
+ it "should return nil when provided an empty xml file" do
13
+ Splitter.split(fixture_path("empty.xml"), @default_options) {}.should be_nil
14
+ end
15
+
16
+ it "should raise an error if start_wrapper is not provided" do
17
+ lambda {
18
+ Splitter.split(fixture_path("empty.xml"), @default_options.reject { |k,v| k == :start_wrapper }) {}
19
+ }.should raise_error
20
+ end
21
+
22
+ it "should raise an error if end_wrapper is not provided" do
23
+ lambda {
24
+ Splitter.split(fixture_path("empty.xml"), @default_options.reject { |k,v| k == :end_wrapper }) {}
25
+ }.should raise_error
26
+ end
27
+
28
+ it "should raise an error if splitter is not provided" do
29
+ lambda {
30
+ Splitter.split(fixture_path("empty.xml"), @default_options.reject { |k,v| k == :splitter }) {}
31
+ }.should raise_error
32
+ end
33
+
34
+ it "should open the correct file" do
35
+ File.should_receive(:open).once.with(fixture_path("empty.xml"))
36
+ Splitter.split(fixture_path("empty.xml"), @default_options) {}
37
+ end
38
+ end
5
39
  end
@@ -5,4 +5,13 @@ require 'splitter'
5
5
  RSpec.configure do |config|
6
6
  config.before do
7
7
  end
8
+ end
9
+
10
+ def fixture_path(filename)
11
+ File.expand_path(File.dirname(__FILE__) + "/fixtures/" + filename)
12
+ end
13
+
14
+ def fixture_file(filename)
15
+ file_path = File.expand_path(File.dirname(__FILE__) + "/fixtures/" + filename)
16
+ File.read(file_path)
8
17
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splitter
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease:
5
- version: 0.0.1
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
6
11
  platform: ruby
7
12
  authors:
8
13
  - Jon Hinson
@@ -10,8 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-09-26 00:00:00 -05:00
14
- default_executable:
18
+ date: 2011-09-26 00:00:00 Z
15
19
  dependencies: []
16
20
 
17
21
  description: Split xml files into smaller pieces.
@@ -30,10 +34,10 @@ files:
30
34
  - Rakefile
31
35
  - lib/splitter.rb
32
36
  - lib/splitter/version.rb
37
+ - spec/fixtures/empty.xml
33
38
  - spec/lib/splitter_spec.rb
34
39
  - spec/spec_helper.rb
35
40
  - splitter.gemspec
36
- has_rdoc: true
37
41
  homepage: ""
38
42
  licenses: []
39
43
 
@@ -47,20 +51,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
51
  requirements:
48
52
  - - ">="
49
53
  - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
50
57
  version: "0"
51
58
  required_rubygems_version: !ruby/object:Gem::Requirement
52
59
  none: false
53
60
  requirements:
54
61
  - - ">="
55
62
  - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
56
66
  version: "0"
57
67
  requirements: []
58
68
 
59
69
  rubyforge_project: splitter
60
- rubygems_version: 1.6.2
70
+ rubygems_version: 1.8.8
61
71
  signing_key:
62
72
  specification_version: 3
63
73
  summary: Split xml files into smaller pieces.
64
74
  test_files:
75
+ - spec/fixtures/empty.xml
65
76
  - spec/lib/splitter_spec.rb
66
77
  - spec/spec_helper.rb