llt-tei_handler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4c68ed6f6c5df8c0e7d02e44261c41ba25599e1
4
+ data.tar.gz: 7528aead71bc6217a8ba3aa4e2d7e9c2f817c6ab
5
+ SHA512:
6
+ metadata.gz: bf561a4a09e51e5de98a8d00c28df1abf64a6cc7d4838291971bc884b769258f79e939d6045ca25bd7415718ee43ecb4e5b069df6ea9945ee22254c12b9687ce
7
+ data.tar.gz: a600bcaef8a7a51525f75a1d7c4b20746bcfcc111eb1e84fa03a613663c080a9d836661f8dbcded6919eda6a62c8a85ccf0a039b00430977c147cbca5c01b58a
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ language: ruby
3
+ before_script:
4
+ - export JRUBY_OPTS=--2.0
5
+ rvm:
6
+ - 2.1.0
7
+ - 2.0.0
8
+ - jruby-1.7.8
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in llt-tei_handler.gemspec
4
+ gemspec
5
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 LFDM
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # LLT::TeiHandler
2
+
3
+ [![Version](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/badge_fury.png)](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/badge_fury)
4
+ [![Dependencies](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/gemnasium.png)](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/gemnasium)
5
+ [![Build Status](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/travis.png)](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/travis)
6
+ [![Coverage](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/coveralls.png)](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/coveralls)
7
+ [![Code Climate](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/code_climate.png)](http://allthebadges.io/latin-language-toolkit/llt-tei_handler/code_climate)
8
+
9
+ Leightweigth transformations of TEI Documents
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'llt-tei_handler'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install llt-tei_handler
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/llt-tei_handler/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,38 @@
1
+ module LLT
2
+ module TeiHandler
3
+ class PreProcessor
4
+ require 'nokogiri'
5
+
6
+ def initialize(document)
7
+ @document = Nokogiri::XML(document)
8
+ raise ArgumentError.new('Document is no TEI XML') unless is_tei?
9
+ end
10
+
11
+ def to_xml
12
+ without_duplicate_declaration(@document.to_xml).strip
13
+ end
14
+
15
+ def is_tei?
16
+ @document.root.name == 'TEI'
17
+ end
18
+
19
+ def ignore_nodes(*nodes)
20
+ @document.search(*nodes).each(&:remove)
21
+ @document
22
+ end
23
+
24
+ alias_method :remove_nodes, :ignore_nodes
25
+
26
+ private
27
+
28
+ DUPLICATE_XML_VERSION = /<\?xml version=.*\?>\s*{2}/m
29
+ def without_duplicate_declaration(doc)
30
+ if doc.match(DUPLICATE_XML_VERSION)
31
+ doc.sub(/^<\?xml version=.*\?>/, '')
32
+ else
33
+ doc
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module LLT
2
+ module TeiHandler
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "llt/tei_handler/version"
2
+
3
+ module LLT
4
+ module TeiHandler
5
+ require 'llt/tei_handler/pre_processor'
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'llt/tei_handler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "llt-tei_handler"
8
+ spec.version = LLT::TeiHandler::VERSION
9
+ spec.authors = ["LFDM"]
10
+ spec.email = ["1986gh@gmail.com"]
11
+ spec.summary = %q{Leightweigth transformations of TEI Documents}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "simplecov", "~> 0.7"
25
+ spec.add_dependency "nokogiri"
26
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::TeiHandler::PreProcessor do
4
+ let(:pre_processor) { LLT::TeiHandler::PreProcessor }
5
+
6
+ def load_fixture(filename)
7
+ File.read(File.expand_path("../../../fixtures/#{filename}", __FILE__))
8
+ end
9
+
10
+ describe "#new" do
11
+ it "takes a TEI xml document on initialization" do
12
+ doc = <<-EOF
13
+ <?xml version="1.0" encoding="utf-8"?>
14
+ <TEI xmlns="http://www.tei-c.org/ns/1.0">
15
+ </TEI>
16
+ EOF
17
+ expect { pre_processor.new(doc) }.not_to raise_error
18
+ end
19
+
20
+ it "throws an error when the document is NOT TEI" do
21
+ doc = <<-EOF
22
+ <?xml version="1.0" encoding="utf-8"?>
23
+ <doc>
24
+ </doc>
25
+ EOF
26
+
27
+ expect { pre_processor.new(doc) }.to raise_error ArgumentError
28
+ end
29
+ end
30
+
31
+ let(:tei_doc) do
32
+ <<-EOF
33
+ <?xml version="1.0" encoding="utf-8"?>
34
+ <TEI xmlns="http://www.tei-c.org/ns/1.0">
35
+ <teiHeader>
36
+ <xxx/>
37
+ </teiHeader>
38
+ <body>
39
+ <head>TITLE</head>
40
+ <p>Text <ref type='note'>Note</ref> resumed</p>
41
+ </body>
42
+ </TEI>
43
+ EOF
44
+ end
45
+
46
+ describe "#ignore_nodes" do
47
+ it "has the alias remove_nodes" do
48
+ doc1 = pre_processor.new(tei_doc)
49
+ doc2 = pre_processor.new(tei_doc)
50
+
51
+ removed = doc1.remove_nodes('body').to_xml
52
+ ignored = doc2.ignore_nodes('body').to_xml
53
+
54
+ removed.should == ignored
55
+ end
56
+
57
+ def with_stripped_lines(string)
58
+ string.lines.map(&:strip).join
59
+ end
60
+
61
+ it "takes out given nodes including all of their content" do
62
+ doc = pre_processor.new(tei_doc)
63
+ doc.ignore_nodes('teiHeader', 'head')
64
+ result = with_stripped_lines(<<-EOF)
65
+ <?xml version="1.0" encoding="utf-8"?>
66
+ <TEI xmlns="http://www.tei-c.org/ns/1.0">
67
+ <body>
68
+ <p>Text <ref type="note">Note</ref> resumed</p>
69
+ </body>
70
+ </TEI>
71
+ EOF
72
+
73
+ with_stripped_lines(doc.to_xml).should == result
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe LLT::TeiHandler do
4
+ it 'has a version number' do
5
+ expect(LLT::TeiHandler::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ Coveralls.wear!
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
13
+ end
14
+
15
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
16
+ require 'llt/tei_handler'
17
+
18
+ RSpec.configure do |config|
19
+ config.treat_symbols_as_metadata_keys_with_true_values = true
20
+ config.run_all_when_everything_filtered = true
21
+ config.filter_run :focus
22
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llt-tei_handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - LFDM
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Leightweigth transformations of TEI Documents
84
+ email:
85
+ - 1986gh@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/llt/tei_handler.rb
98
+ - lib/llt/tei_handler/pre_processor.rb
99
+ - lib/llt/tei_handler/version.rb
100
+ - llt-tei_handler.gemspec
101
+ - spec/lib/llt/tei_handler/pre_processor_spec.rb
102
+ - spec/lib/llt/tei_handler_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.0
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Leightweigth transformations of TEI Documents
128
+ test_files:
129
+ - spec/lib/llt/tei_handler/pre_processor_spec.rb
130
+ - spec/lib/llt/tei_handler_spec.rb
131
+ - spec/spec_helper.rb