citero 1.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,209 @@
1
+ module Citero
2
+ module Outputs
3
+ class Ris
4
+ def initialize(csf)
5
+ @csf = csf.csf
6
+ end
7
+
8
+ def to_ris
9
+ output = ""
10
+ output_order.each do |method_sym|
11
+ output += send(method_sym)
12
+ end
13
+ output
14
+ end
15
+
16
+ private
17
+
18
+ def ris_output_line(key,value)
19
+ output = ""
20
+ return output if value.nil?
21
+ if value.is_a?(Array)
22
+ value.each {|val| output += "#{key} - #{val}\n" }
23
+ else
24
+ output += "#{key} - #{value}\n"
25
+ end
26
+ output
27
+ end
28
+
29
+ def output_type
30
+ ris_output_line('TY', (type_output_map[@csf['itemType']] || "BOOK"))
31
+ end
32
+
33
+ def output_author
34
+ ris_output_line('A1', @csf['author'])
35
+ end
36
+
37
+ def output_title
38
+ ris_output_line('TI', @csf['title'])
39
+ end
40
+
41
+ def output_bookTitle
42
+ ris_output_line('BT', @csf['bookTitle'])
43
+ end
44
+
45
+ def output_publicationTitle
46
+ ris_output_line('JO', @csf['publicationTitle'])
47
+ end
48
+
49
+ def output_backupPublicationTitle
50
+ ris_output_line('T2', @csf['backupPublicationTitle'])
51
+ end
52
+
53
+ def output_editor
54
+ ris_output_line('ED', @csf['editor'])
55
+ end
56
+
57
+ def output_contributor
58
+ ris_output_line('A2', @csf['contributor'])
59
+ end
60
+
61
+ def output_assignee
62
+ ris_output_line('A2', @csf['assignee'])
63
+ end
64
+
65
+ def output_volume
66
+ ris_output_line('VL', @csf['volume'])
67
+ end
68
+
69
+ def output_applicationNumber
70
+ ris_output_line('VL', @csf['applicationNumber'])
71
+ end
72
+
73
+ def output_reportNumber
74
+ ris_output_line('VL', @csf['reportNumber'])
75
+ end
76
+
77
+ def output_issue
78
+ ris_output_line('IS', @csf['issue'])
79
+ end
80
+
81
+ def output_patentNumber
82
+ ris_output_line('IS', @csf['patentNumber'])
83
+ end
84
+
85
+ def output_publisher
86
+ ris_output_line('PB', @csf['publisher'])
87
+ end
88
+
89
+ def output_references
90
+ ris_output_line('PB', @csf['references'])
91
+ end
92
+
93
+ def output_place
94
+ ris_output_line('CY', @csf['place'])
95
+ end
96
+
97
+ def output_date
98
+ ris_output_line('PY', @csf['date']&.first)
99
+ end
100
+
101
+ def output_filingDate
102
+ ris_output_line('Y2', @csf['filingDate'])
103
+ end
104
+
105
+ def output_abstractNote
106
+ ris_output_line('N2', @csf['abstractNote'])
107
+ end
108
+
109
+ def output_startPage
110
+ ris_output_line('SP', @csf['startPage'])
111
+ end
112
+
113
+ def output_endPage
114
+ ris_output_line('EP', @csf['endPage'])
115
+ end
116
+
117
+ def output_isbn
118
+ ris_output_line('SN', @csf['isbn'])
119
+ end
120
+
121
+ def output_issn
122
+ ris_output_line('SN', @csf['issn'])
123
+ end
124
+
125
+ def output_url
126
+ ris_output_line('UR', @csf['url'])
127
+ end
128
+
129
+ def output_tags
130
+ ris_output_line('KW', @csf['tags']&.sort)
131
+ end
132
+
133
+ def output_ris_end
134
+ "ER -\n\n"
135
+ end
136
+
137
+ def output_order
138
+ [
139
+ :output_type,
140
+ :output_author,
141
+ :output_publisher,
142
+ :output_place,
143
+ :output_isbn,
144
+ :output_issn,
145
+ :output_title,
146
+ :output_bookTitle,
147
+ :output_publicationTitle,
148
+ :output_backupPublicationTitle,
149
+ :output_editor,
150
+ :output_contributor,
151
+ :output_assignee,
152
+ :output_volume,
153
+ :output_applicationNumber,
154
+ :output_reportNumber,
155
+ :output_issue,
156
+ :output_patentNumber,
157
+ :output_references,
158
+ :output_date,
159
+ :output_filingDate,
160
+ :output_abstractNote,
161
+ :output_startPage,
162
+ :output_endPage,
163
+ :output_url,
164
+ :output_tags,
165
+ :output_ris_end
166
+ ]
167
+ end
168
+
169
+ def type_output_map
170
+ @type_output_map ||= {
171
+ "book" => "BOOK",
172
+ "bookSection" => "CHAP",
173
+ "journalArticle" => "JOUR",
174
+ "journal" => "JFULL",
175
+ "magazineArticle" => "MGZN",
176
+ "newspaperArticle" => "NEWS",
177
+ "thesis" => "THES",
178
+ "dissertation" => "THES",
179
+ "letter" => "PCOMM",
180
+ "interview" => "PCOMM",
181
+ "manuscript" => "PAMP",
182
+ "film" => "MPCT",
183
+ "artwork" => "ART",
184
+ "report" => "RPRT",
185
+ "bill" => "BILL",
186
+ "case" => "CASE",
187
+ "hearing" => "HEAR",
188
+ "patent" => "PAT",
189
+ "statute" => "STAT",
190
+ "map" => "MAP",
191
+ "blogPost" => "ELEC",
192
+ "webpage" => "ELEC",
193
+ "instantMessage" => "ICOMM",
194
+ "forumPost" => "ICOMM",
195
+ "email" => "ICOMM",
196
+ "audioRecording" => "SOUND",
197
+ "videoRecording" => "VIDEO",
198
+ "computerProgram" => "COMP",
199
+ "conferencePaper" => "CONF",
200
+ "tvBroadcast" => "GEN",
201
+ "presentation" => "GEN",
202
+ "radioBroadcast" => "GEN",
203
+ "podcast" => "GEN",
204
+ "document" => "GEN"
205
+ }
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,5 @@
1
+ module Citero
2
+ module Utils
3
+ require_relative 'utils/name_formatter'
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ module Citero
2
+ module Utils
3
+ class NameFormatter
4
+ attr_reader :first_name, :middle_name, :last_name
5
+ def initialize(raw_name)
6
+ return unless raw_name
7
+ raw_name_array = raw_name.gsub(/\(.*\)/, "").gsub(",", ", ").gsub(/\s+/, " ").split
8
+ raw_name_array.each_with_index do |name, index|
9
+ if (name.include?(",") && index == 0)
10
+ @last_name = name.gsub(",", "")
11
+ elsif (index == 0 && @last_name.nil?)
12
+ @first_name = name.gsub(",", "")
13
+ elsif (index == 1 && @first_name.nil? && @last_name)
14
+ @first_name = name.gsub(",", "")
15
+ elsif (index >= 1 && @first_name && index < raw_name_array.length - 1)
16
+ @middle_name = (@middle_name ? "#{@middle_name} " : "") + name.gsub(",", "")
17
+ elsif (@first_name && @middle_name && name.match(/[a-zA-Z]+/))
18
+ @last_name = name.gsub(",", "")
19
+ elsif (index > 1 && @first_name && @last_name)
20
+ if (name.match(/[a-zA-Z\-'\.]+/))
21
+ @middle_name = (@middle_name ? "#{middle_name} " : "") + name.gsub(",", "");
22
+ elsif (name.match(/[a-zA-Z\.0-9]{1,4}/))
23
+ @suffix = name;
24
+ end
25
+ end
26
+ if (index == raw_name_array.length - 1 && !@last_name)
27
+ if(!@middle_name)
28
+ @last_name = name unless name == @first_name
29
+ else
30
+ @last_name = @middle_name.split.last
31
+ @middle_name = (@middle_name.split - @last_name.split).join
32
+ end
33
+ end
34
+ end
35
+
36
+ @first_name = nil if first_name&.empty?
37
+ @middle_name = nil if middle_name&.empty?
38
+ @last_name = nil if last_name&.empty?
39
+ @suffix = nil if @suffix&.empty?
40
+
41
+ @first_name = @first_name.strip if first_name
42
+ @middle_name = @middle_name.strip if middle_name
43
+ @last_name = @last_name.strip if last_name
44
+ @suffix = @suffix.strip if @suffix
45
+
46
+ end
47
+ def to_standardized
48
+ str_builder = ""
49
+ str_builder = "#{last_name.strip}, " if last_name
50
+ str_builder = "#{str_builder}#{first_name.strip}" if first_name
51
+ str_builder = "#{str_builder} #{middle_name.strip}" if middle_name
52
+ str_builder
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module Citero
2
+ VERSION = "1.0.0.alpha"
3
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: citero
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - hab278
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ox
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.6
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.5.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.5.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.8.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.8.0
111
+ description: Tool to translate between bibliographic formats.
112
+ email: hab278@nyu.edu
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - Gemfile
118
+ - README.md
119
+ - Rakefile
120
+ - lib/citero.rb
121
+ - lib/citero/csf.rb
122
+ - lib/citero/inputs.rb
123
+ - lib/citero/inputs/openurl.rb
124
+ - lib/citero/inputs/pnx.rb
125
+ - lib/citero/inputs/readers.rb
126
+ - lib/citero/inputs/readers/pnx_reader.rb
127
+ - lib/citero/outputs.rb
128
+ - lib/citero/outputs/bibtex.rb
129
+ - lib/citero/outputs/easybib.rb
130
+ - lib/citero/outputs/openurl.rb
131
+ - lib/citero/outputs/refworks_tagged.rb
132
+ - lib/citero/outputs/ris.rb
133
+ - lib/citero/utils.rb
134
+ - lib/citero/utils/name_formatter.rb
135
+ - lib/citero/version.rb
136
+ homepage: https://github.com/NYULibraries/citero-ruby
137
+ licenses: []
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.3.1
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.11
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Tool to translate between bibliographic formats.
159
+ test_files: []