jats 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 313ee2fe8532319f7b1aab77c0121a269c0d017f
4
+ data.tar.gz: d4087afdd6b0283a194543aaae98e927f22d23a8
5
+ SHA512:
6
+ metadata.gz: 64d2aa4db8e064376a1fae73d8353ac32f2c42cb97b60a346d5255c62d68434a6f8f2bc49faea637b8a1d9af1e984ecc8421f1b6304c6b9720921ec3b8732ba0
7
+ data.tar.gz: dfab7e8bfa74b242ca15f1d692aef6e5ad4329b9565bab0c16f941e800ceee715ceed009795c0b80b05cf7d7a250ad9f7f84e12b373bf116a0f80da6bd09d6f7
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", ">= 0"
5
+ gem "rdoc", "~> 3.12"
6
+ gem "bundler", "~> 1.0"
7
+ gem "jeweler", "~> 1.8.7"
8
+ gem "simplecov", ">= 0"
9
+ gem 'guard'
10
+ gem 'guard-rspec'
11
+ end
@@ -0,0 +1,99 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ coderay (1.0.9)
7
+ diff-lcs (1.2.4)
8
+ faraday (0.8.8)
9
+ multipart-post (~> 1.2.0)
10
+ ffi (1.9.0)
11
+ formatador (0.2.4)
12
+ git (1.2.6)
13
+ github_api (0.10.1)
14
+ addressable
15
+ faraday (~> 0.8.1)
16
+ hashie (>= 1.2)
17
+ multi_json (~> 1.4)
18
+ nokogiri (~> 1.5.2)
19
+ oauth2
20
+ guard (1.8.2)
21
+ formatador (>= 0.2.4)
22
+ listen (>= 1.0.0)
23
+ lumberjack (>= 1.0.2)
24
+ pry (>= 0.9.10)
25
+ thor (>= 0.14.6)
26
+ guard-rspec (3.0.2)
27
+ guard (>= 1.8)
28
+ rspec (~> 2.13)
29
+ hashie (2.0.5)
30
+ highline (1.6.19)
31
+ httpauth (0.2.0)
32
+ jeweler (1.8.7)
33
+ builder
34
+ bundler (~> 1.0)
35
+ git (>= 1.2.5)
36
+ github_api (= 0.10.1)
37
+ highline (>= 1.6.15)
38
+ nokogiri (= 1.5.10)
39
+ rake
40
+ rdoc
41
+ json (1.8.0)
42
+ jwt (0.1.8)
43
+ multi_json (>= 1.5)
44
+ listen (1.3.0)
45
+ rb-fsevent (>= 0.9.3)
46
+ rb-inotify (>= 0.9)
47
+ rb-kqueue (>= 0.2)
48
+ lumberjack (1.0.4)
49
+ method_source (0.8.2)
50
+ multi_json (1.7.9)
51
+ multi_xml (0.5.5)
52
+ multipart-post (1.2.0)
53
+ nokogiri (1.5.10)
54
+ oauth2 (0.9.2)
55
+ faraday (~> 0.8)
56
+ httpauth (~> 0.2)
57
+ jwt (~> 0.1.4)
58
+ multi_json (~> 1.0)
59
+ multi_xml (~> 0.5)
60
+ rack (~> 1.2)
61
+ pry (0.9.12.2)
62
+ coderay (~> 1.0.5)
63
+ method_source (~> 0.8)
64
+ slop (~> 3.4)
65
+ rack (1.5.2)
66
+ rake (10.1.0)
67
+ rb-fsevent (0.9.3)
68
+ rb-inotify (0.9.1)
69
+ ffi (>= 0.5.0)
70
+ rb-kqueue (0.2.0)
71
+ ffi (>= 0.5.0)
72
+ rdoc (3.12.2)
73
+ json (~> 1.4)
74
+ rspec (2.14.1)
75
+ rspec-core (~> 2.14.0)
76
+ rspec-expectations (~> 2.14.0)
77
+ rspec-mocks (~> 2.14.0)
78
+ rspec-core (2.14.5)
79
+ rspec-expectations (2.14.2)
80
+ diff-lcs (>= 1.1.3, < 2.0)
81
+ rspec-mocks (2.14.3)
82
+ simplecov (0.7.1)
83
+ multi_json (~> 1.0)
84
+ simplecov-html (~> 0.7.1)
85
+ simplecov-html (0.7.1)
86
+ slop (3.4.6)
87
+ thor (0.18.1)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ bundler (~> 1.0)
94
+ guard
95
+ guard-rspec
96
+ jeweler (~> 1.8.7)
97
+ rdoc (~> 3.12)
98
+ rspec
99
+ simplecov
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec 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{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ 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"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Bart Zonneveld
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = jats
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to jats
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Bart Zonneveld. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "jats"
18
+ gem.homepage = "http://github.com/bartzon/jats"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Parse Journal Publishing Tag Set into sensible Ruby}
21
+ gem.description = %Q{This gem converts a Journal Publishing Tag Set (Jats) XML file into a ruby hash compatible with the Lens document format}
22
+ gem.email = "bart@madebyhiro.com"
23
+ gem.authors = ["Bart Zonneveld"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec)
31
+ task :default => :spec
32
+
33
+ require 'rdoc/task'
34
+ Rake::RDocTask.new do |rdoc|
35
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
36
+
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = "jats #{version}"
39
+ rdoc.rdoc_files.include('README*')
40
+ rdoc.rdoc_files.include('lib/**/*.rb')
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,100 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "jats"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bart Zonneveld"]
12
+ s.date = "2013-08-22"
13
+ s.description = "This gem converts a Journal Publishing Tag Set (Jats) XML file into a ruby hash compatible with the Lens document format"
14
+ s.email = "bart@madebyhiro.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "Guardfile",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "jats.gemspec",
30
+ "lib/jats.rb",
31
+ "lib/jats/affiliation.rb",
32
+ "lib/jats/annotation.rb",
33
+ "lib/jats/article.rb",
34
+ "lib/jats/body.rb",
35
+ "lib/jats/figure.rb",
36
+ "lib/jats/front.rb",
37
+ "lib/jats/heading.rb",
38
+ "lib/jats/node.rb",
39
+ "lib/jats/person.rb",
40
+ "lib/jats/text.rb",
41
+ "spec/fixtures/affiliation.xml",
42
+ "spec/fixtures/annotation.xml",
43
+ "spec/fixtures/bmj_sample.xml",
44
+ "spec/fixtures/figure.xml",
45
+ "spec/fixtures/heading.xml",
46
+ "spec/fixtures/peerj.xml",
47
+ "spec/fixtures/person.xml",
48
+ "spec/fixtures/plos_one.xml",
49
+ "spec/fixtures/pnas_sample.xml",
50
+ "spec/fixtures/text.xml",
51
+ "spec/jats/affiliation_spec.rb",
52
+ "spec/jats/annotation_spec.rb",
53
+ "spec/jats/article_spec.rb",
54
+ "spec/jats/body_spec.rb",
55
+ "spec/jats/figure_spec.rb",
56
+ "spec/jats/front_spec.rb",
57
+ "spec/jats/heading_spec.rb",
58
+ "spec/jats/node_spec.rb",
59
+ "spec/jats/person_spec.rb",
60
+ "spec/jats/text_spec.rb",
61
+ "spec/jats_spec.rb",
62
+ "spec/spec_helper.rb"
63
+ ]
64
+ s.homepage = "http://github.com/bartzon/jats"
65
+ s.licenses = ["MIT"]
66
+ s.require_paths = ["lib"]
67
+ s.rubygems_version = "2.0.6"
68
+ s.summary = "Parse Journal Publishing Tag Set into sensible Ruby"
69
+
70
+ if s.respond_to? :specification_version then
71
+ s.specification_version = 4
72
+
73
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
+ s.add_development_dependency(%q<rspec>, [">= 0"])
75
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
76
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
77
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
78
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
79
+ s.add_development_dependency(%q<guard>, [">= 0"])
80
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
81
+ else
82
+ s.add_dependency(%q<rspec>, [">= 0"])
83
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
84
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
85
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
86
+ s.add_dependency(%q<simplecov>, [">= 0"])
87
+ s.add_dependency(%q<guard>, [">= 0"])
88
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
89
+ end
90
+ else
91
+ s.add_dependency(%q<rspec>, [">= 0"])
92
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
93
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
94
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
95
+ s.add_dependency(%q<simplecov>, [">= 0"])
96
+ s.add_dependency(%q<guard>, [">= 0"])
97
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
98
+ end
99
+ end
100
+
@@ -0,0 +1,15 @@
1
+ module Jats
2
+ autoload :Article, 'jats/article'
3
+
4
+ autoload :Front, 'jats/front'
5
+ autoload :Body, 'jats/body'
6
+
7
+ autoload :Node, 'jats/node'
8
+ autoload :Person, 'jats/person'
9
+ autoload :Heading, 'jats/heading'
10
+ autoload :Text, 'jats/text'
11
+ autoload :Figure, 'jats/figure'
12
+ autoload :Annotation, 'jats/annotation'
13
+ autoload :Affiliation, 'jats/affiliation'
14
+
15
+ end
@@ -0,0 +1,13 @@
1
+ module Jats
2
+ class Affiliation < Node
3
+ def to_hash
4
+ {
5
+ label: xml.css('label').text,
6
+ department: xml.css('institution').text.gsub(/^\W+|\W+$/, ''),
7
+ address: xml.css('addr-line').text,
8
+ country: xml.css('country').text
9
+ }
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,17 @@
1
+ module Jats
2
+ class Annotation < Node
3
+ attr_accessor :source
4
+
5
+ def attributes
6
+ rid = xml['rid']
7
+ id = rid.gsub('ref-', '')
8
+
9
+ {
10
+ source: source,
11
+ content: xml.text,
12
+ target: "article:bib#{id}"
13
+ }
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,38 @@
1
+ module Jats
2
+ class Article
3
+ include Front
4
+ include Body
5
+
6
+ attr_accessor :xml, :doc
7
+
8
+ def self.from_xml(xml)
9
+ new(xml).parse
10
+ end
11
+
12
+ def initialize(xml=nil)
13
+ @xml = xml
14
+ @doc = { properties: {} }
15
+ @doc[:nodes] = {}
16
+ @doc[:views] = { content: [] }
17
+ end
18
+
19
+ def add_to_outline(node)
20
+ doc[:views][:content] << node.name
21
+ end
22
+
23
+ def add_node(node)
24
+ doc[:nodes].merge!(node.to_hash)
25
+ end
26
+
27
+ def parse_back
28
+ # TODO implement
29
+ end
30
+
31
+ def parse
32
+ parse_front
33
+ parse_body
34
+ parse_back
35
+ doc
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ module Jats
2
+ module Body
3
+ def parse_sec(xml)
4
+ sec = Heading.from_xml(xml)
5
+ add_to_outline(sec)
6
+ add_node(sec)
7
+ end
8
+
9
+ def parse_p(xml)
10
+ p = Text.from_xml(xml)
11
+ add_to_outline(p)
12
+ add_node(p)
13
+ p.annotations.each { |a| add_node(a) }
14
+ end
15
+
16
+ def parse_fig(xml)
17
+ fig = Figure.from_xml(xml)
18
+ add_to_outline(fig)
19
+ add_node(fig)
20
+ end
21
+
22
+ def nodes
23
+ xml.xpath('//sec | //sec /p | //fig')
24
+ end
25
+
26
+ def parse_body
27
+ nodes.each do |node|
28
+ next if node.text?
29
+
30
+ if respond_to?("parse_#{node.name}")
31
+ self.send("parse_#{node.name}", node)
32
+ end
33
+ end
34
+
35
+ doc
36
+ end
37
+ end
38
+ end
39
+