citero-jruby 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
@@ -0,0 +1,45 @@
1
+ citero-jruby
2
+ ======================
3
+ [![Build Status](http://jenkins1.bobst.nyu.edu/view/Citation/job/citero-jruby/badge/icon)](http://jenkins1.bobst.nyu.edu/view/Citation/job/citero-jruby/)
4
+ [![Build Status](https://secure.travis-ci.org/NYULibraries/citero-jruby.png?branch=master)](http://travis-ci.org/NYULibraries/citero-jruby)
5
+ [![Dependency Status](https://gemnasium.com/NYULibraries/citero-jruby.png)](https://gemnasium.com/NYULibraries/citero-jruby)
6
+ [![Code Climate](https://codeclimate.com/github/NYULibraries/citero-jruby.png)](https://codeclimate.com/github/NYULibraries/citero-jruby)
7
+ [![Gem Version](https://badge.fury.io/rb/citero-jruby.png)](http://badge.fury.io/rb/citero-jruby)
8
+ [![Coverage Status](https://coveralls.io/repos/NYULibraries/citero-jruby/badge.png?branch=master)](https://coveralls.io/r/NYULibraries/citero-jruby)
9
+
10
+
11
+ A JRuby wrapper for the Citero, enables use of the Citero in JRuby. See [Citero](https://github.com/NYULibraries/citero).
12
+
13
+ Usage Details
14
+ ==============
15
+
16
+ To use Citero simply pass in your data into the Citero module via the map method. Then call the method that specifies the from format and
17
+ the method that specifies what format you want to translate to.
18
+
19
+
20
+ Citero.map("itemType: book").from\_csf.to_ris # Returns a string with the value TY - BOOK\n\nER -\n\n
21
+
22
+
23
+ You can find available formats via:
24
+
25
+ Citero.from_formats # List of from formats (Array)
26
+ # pnx, xerxes_xml, ris, openurl, bibtex, csf*
27
+ Citero.to_formats # List of to formats (Array)
28
+ # ris, openurl, bibtex, easybib, csf*
29
+ *CSF is Citero Standard Form, it's an internal mapping DSL.
30
+
31
+ To call a method, simply append the format name after either from\_ or to\_.
32
+ Note, you must call from\_ before to\_ and map before anything else.
33
+
34
+ csf = Citero.map("itemType: book").from_csf
35
+ csf.to_ris # -> TY - BOOK\n\nER -\n\n
36
+ csf.to_openurl # -> rft.ulr_ver=Z39.88-2004&rft.ctx_ver=Z39.88-2004&rft.rfr_id=info:sid/libraries.nyu.edu:citero&rft_val_fmlt=info:ofi/fmt:kev:mtx:book&rft.genre=book
37
+ csf.to_easybib # -> {"source":"book","book":{"title":null},"pubtype":{"main":"pubnonperiodical"},"pubnonperiodical":{},"contributors":[{}]}
38
+ csf.to_bibtex # -> @book{????}
39
+
40
+ Finally, this gem allows you to interact with the CSF object, you can call the _csf_ method.
41
+
42
+ rec = Citero.map("itemType: book").from_csf
43
+ csf = rec.csf
44
+ p csf.itemType # => Prints ['book']
45
+ p csf.keys # => Prints ['itemType']
@@ -0,0 +1,58 @@
1
+ require 'rake/testtask'
2
+ require 'git'
3
+ require 'fileutils'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ require "bundler/gem_tasks"
8
+ rescue LoadError
9
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
10
+ end
11
+
12
+ begin
13
+ require 'rdoc/task'
14
+ rescue LoadError
15
+ require 'rdoc/rdoc'
16
+ require 'rake/rdoctask'
17
+ RDoc::Task = Rake::RDocTask
18
+ end
19
+
20
+ RDoc::Task.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = 'doc'
22
+ rdoc.title = 'citero-jruby'
23
+ rdoc.options << '--line-numbers'
24
+ rdoc.options << '--markup markdown'
25
+ rdoc.rdoc_files.include('README.md')
26
+ rdoc.rdoc_files.include('app/**/*.rb')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ Rake::TestTask.new do |t|
31
+ t.libs << 'test'
32
+ t.test_files = FileList['test/*.rb']
33
+ t.verbose = true
34
+ end
35
+
36
+ desc "Push latest rdoc and rdocs to gh-pages"
37
+ task :ghpages do
38
+ g = Git.open(Dir.pwd)
39
+ FileUtils.mv("coverage/", "coverage.bak/", :force => true)
40
+ FileUtils.mv("doc/", "doc.bak/", :force => true)
41
+ g.checkout(g.branch('gh-pages'))
42
+ g.pull("origin", "gh-pages")
43
+ FileUtils.rm_r("coverage", :force => true)
44
+ FileUtils.mv("coverage.bak/", "coverage/", :force => true)
45
+ FileUtils.rm_r("doc", :force => true)
46
+ FileUtils.mv("doc.bak/", "doc/", :force => true)
47
+ g.add(".")
48
+ g.commit_all("Update coverage and rdocs.")
49
+ g.push("origin", "gh-pages")
50
+ FileUtils.cp_r("coverage/", "coverage.bak/")
51
+ FileUtils.cp_r("doc/", "doc.bak/")
52
+ g.checkout(g.branch('devel'))
53
+ FileUtils.mv("coverage.bak/", "coverage/", :force => true)
54
+ FileUtils.mv("doc.bak/", "doc/", :force => true)
55
+ end
56
+
57
+ desc "Run tests"
58
+ task :default => :test
@@ -0,0 +1 @@
1
+ require 'citero-jruby/base'
@@ -0,0 +1,56 @@
1
+ module Citero
2
+
3
+ # Java is required in this module.
4
+ require 'java'
5
+ require 'citero-jruby/citero.jar'
6
+
7
+ #CSF class, used to interact directly with available metadata.
8
+ class CSF
9
+ # CSF object from Citero that is to be used
10
+ CSF = Java::EduNyuLibraryCitero::CSF
11
+
12
+ # Initialize the CSF object with data
13
+ def initialize data
14
+ @csf = CSF::new(data)
15
+ end
16
+
17
+ # The method_missing override checks to see if the called method
18
+ # can be evaluated to a key, then stores it and calls it if it can.
19
+ # For example, .itemType or .authors.
20
+ def method_missing(meth, *args, &block)
21
+ # Check to see if it can be evaluated
22
+ if(matches? meth)
23
+ #Defines the method and caches it to the class
24
+ self.class.send(:define_method, meth) do
25
+ # Splits the method and parameter. See formatize and directionize
26
+ @csf::config()::getStringArray(meth.to_s).to_a
27
+ end
28
+ # calls the method
29
+ send meth, *args, &block
30
+ else
31
+ super
32
+ end
33
+ end
34
+
35
+ # Returns true if the method can be evaluated to a key
36
+ def respond_to? meth, include_private=false
37
+ if(matches? meth)
38
+ return true
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ # Private method. Checks to see if the method name is a valid key
45
+ # for the configuration file.
46
+ def matches? meth
47
+ @csf::config()::containsKey(meth.to_s)
48
+ end
49
+ private :matches?
50
+
51
+ # A list of keys that is available in this properties configuration
52
+ def keys
53
+ @keys ||= Array.new(@csf::config()::getKeys.collect {|key| key})
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,148 @@
1
+ require 'citero-jruby/CSF'
2
+ # Citero class, used in builder form as Citero.map("some data").from_format.to_format
3
+ module Citero
4
+
5
+ # Import of an important java enum type
6
+ java_import Java::EduNyuLibraryCitero::Formats
7
+
8
+ # Calling the map method creates a new instance of the Base class, with splatter operator passed in
9
+ def self.map *args
10
+ Base.new *args
11
+ end
12
+
13
+ # List of available formats Citero exports to as a module class method for quick checks.
14
+ def self.to_formats
15
+ @to_formats ||= formats :isDestinationFormat
16
+ end
17
+
18
+ # List of available formats Citero exports from as a module class method for quick checks.
19
+ def self.from_formats
20
+ @from_formats ||= formats :isSourceFormat
21
+ end
22
+
23
+ private
24
+ def self.formats meth
25
+ Formats::values.select {|format| format.send(meth) }.collect {|format| format.name.downcase}
26
+ end
27
+
28
+ # The Base class is the true wrapper for citation
29
+ class Base
30
+
31
+ # Import of important java files.
32
+ JavaCitero = Java::EduNyuLibraryCitero::Citero
33
+
34
+
35
+ # The constructor, takes input data taken from the parent module
36
+ # and creates an instance of the Citero java object.
37
+ # Returns itself for builder patttern.
38
+ def initialize data
39
+ @citero = JavaCitero::map(data)
40
+ self
41
+ end
42
+
43
+ # The from method is private, it takes in a format and gets
44
+ # the appropriate Format java class and then calls
45
+ # the from method in the Citero java object and stores its
46
+ # return value in an instance variable.
47
+ # Returns itself.
48
+ def from format
49
+ #Formats are enums in java, so they are all uppercase
50
+ @citero = @citero::from(Formats::valueOf(format.upcase))
51
+ self
52
+ #rescue any exceptions, if the error is not caught in JAR, most likely a
53
+ #problem with the data
54
+ rescue Exception => e
55
+ raise TypeError, "Mismatched data for #{format}"
56
+ end
57
+ private :from
58
+
59
+ # The to method is private, it takes in a format and gets
60
+ # the appropriate Format java class and then calls
61
+ # the to method in the Citero java object and returns the
62
+ # return value as a string.
63
+ def to format
64
+ #Formats are enums in java, so they are all uppercase
65
+ @citero::to(Formats::valueOf(format.upcase))
66
+ #rescue any exceptions, if the error is not caught in JAR, most likely a
67
+ #problem with the source format
68
+ rescue Exception => e
69
+ raise ArgumentError, "Missing a source format. Use from_[format] first."
70
+ end
71
+ private :to
72
+
73
+ # Returns a CSF object
74
+ def csf
75
+ CSF::new(self.to_csf)
76
+ # Rescue all exceptions, but mostly likeley a problem with the source format.
77
+ rescue Exception => e
78
+ raise ArgumentError, "Missing a source format. Use from_[format] first."
79
+ end
80
+
81
+ # The method_missing override checks to see if the called method
82
+ # can be evaluated to a method name and parameter, then stores it
83
+ # and calls it if it can.
84
+ # For example, to_csf or from_pnx. pnx_to will not work.
85
+ def method_missing(meth, *args, &block)
86
+ # Check to see if it can be evaluated
87
+ if(matches? meth)
88
+ #Defines the method and caches it to the class
89
+ self.class.send(:define_method, meth) do
90
+ # Splits the method and parameter. See formatize and directionize
91
+ send directionize(meth).to_sym, formatize(meth)
92
+ end
93
+ # calls the method
94
+ send meth, *args, &block
95
+ else
96
+ super
97
+ end
98
+ end
99
+
100
+ # Returns true if the method can be evaluated to a method name
101
+ # and parameter.
102
+ def respond_to? meth, include_private=false
103
+ if(matches? meth)
104
+ return true
105
+ else
106
+ super
107
+ end
108
+ end
109
+
110
+ # Private method. Checks to see if the method name is in the list of methods
111
+ # that can accept the formats, and checks to see if the formats are in a list
112
+ # of formats as defined by the Java enum Format.
113
+ def matches? meth
114
+ directions.include? directionize(meth) and method("#{directionize(meth)}_formats").call.include? formatize(meth)
115
+ end
116
+ private :matches?
117
+
118
+ # Splits the method to get its direction, or method ie to and from.
119
+ def directionize meth, delimiter="_"
120
+ meth.to_s.split(delimiter, 2).first
121
+ end
122
+ private :directionize
123
+
124
+ # Splits the method to get its format, or parameter ie csf or ris.
125
+ def formatize meth, delimiter="_"
126
+ meth.to_s.split(delimiter, 2).last
127
+ end
128
+ private :formatize
129
+
130
+ # List of available directions or methods.
131
+ def directions
132
+ @directions ||= ["to", "from"]
133
+ end
134
+ private :directions
135
+
136
+ # List of available formats Citero exports to.
137
+ def to_formats
138
+ @to_formats ||= Citero.to_formats
139
+ end
140
+ private :to_formats
141
+
142
+ # List of available formats Citero exports from.
143
+ def from_formats
144
+ @from_formats ||= Citero.from_formats
145
+ end
146
+ private :from_formats
147
+ end
148
+ end
@@ -0,0 +1,4 @@
1
+ module Citero
2
+ # Citeros current version
3
+ VERSION = "1.0.1"
4
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: citero-jruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.1
6
+ platform: ruby
7
+ authors:
8
+ - hab278
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '10.0'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: test-unit
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.5'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.5'
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.7'
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: '0.7'
59
+ none: false
60
+ prerelease: false
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov-rcov
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.2'
75
+ none: false
76
+ prerelease: false
77
+ type: :development
78
+ - !ruby/object:Gem::Dependency
79
+ name: git
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.2'
85
+ none: false
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.2'
91
+ none: false
92
+ prerelease: false
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ name: json
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '1.7'
101
+ none: false
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '1.7'
107
+ none: false
108
+ prerelease: false
109
+ type: :development
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.2'
117
+ none: false
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.2'
123
+ none: false
124
+ prerelease: false
125
+ type: :development
126
+ - !ruby/object:Gem::Dependency
127
+ name: coveralls
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: !binary |-
133
+ MA==
134
+ none: false
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: !binary |-
140
+ MA==
141
+ none: false
142
+ prerelease: false
143
+ type: :development
144
+ description: Leverages a Maven and a custom JAR and wraps it with JRuby
145
+ email: hab278@nyu.edu
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - lib/citero-jruby.rb
151
+ - lib/citero-jruby/base.rb
152
+ - lib/citero-jruby/citero.jar
153
+ - lib/citero-jruby/CSF.rb
154
+ - lib/citero-jruby/version.rb
155
+ - Rakefile
156
+ - Gemfile
157
+ - README.md
158
+ homepage:
159
+ licenses: []
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ segments:
169
+ - 0
170
+ hash: 2
171
+ version: !binary |-
172
+ MA==
173
+ none: false
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ segments:
179
+ - 0
180
+ hash: 2
181
+ version: !binary |-
182
+ MA==
183
+ none: false
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 1.8.24
187
+ signing_key:
188
+ specification_version: 3
189
+ summary: Tool to translate between bibliographic formats.
190
+ test_files: []