bibtowiki 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/bibtowiki.rb +59 -0
  2. metadata +58 -0
@@ -0,0 +1,59 @@
1
+ require 'bibtex'
2
+ require 'active_support'
3
+ module BibTeX
4
+ class Entry
5
+ def to_wikipedia(with_reftag=true)
6
+ props = ActiveSupport::OrderedHash.new
7
+
8
+ # authors
9
+ if authors != nil
10
+ if authors.size == 1
11
+ # conditional is because some authors might not have first names
12
+ # ('Teller' in Penn & Teller, maybe)
13
+ props[:first] = authors[0].first if authors[0].first != nil
14
+ props[:last] = authors[0].last
15
+ elsif authors.size > 1
16
+ author_count = 0
17
+ authors[0..([authors.size, 8].min - 1)].each do |author|
18
+ author_count += 1
19
+ props[("first" + author_count.to_s).to_sym] = author.first if author.first != nil
20
+ props[("last" + author_count.to_s).to_sym] = author.last
21
+ end
22
+ #if authors.size >= 9
23
+ # props[:others] = authors[8..-1].map {|i| i[:first] + " " + i[:last] }.join(", ")
24
+ #end
25
+ end
26
+ end
27
+
28
+ # common keys
29
+ emdash = 2014.chr('UTF-8')
30
+ props[:title] = fields[:title].to_s if fields.has_key?(:title)
31
+ props[:year] = fields[:year].to_s if fields.has_key?(:year)
32
+ props[:pages] = fields[:pages].to_s.sub("---", emdash).sub("--", emdash) if fields.has_key?(:pages)
33
+ props[:journal] = fields[:journal].to_s if fields.has_key?(:journal)
34
+ props[:volume] = fields[:volume].to_s if fields.has_key?(:volume)
35
+ props[:number] = fields[:number].to_s if fields.has_key?(:number)
36
+
37
+ out = ""
38
+ if with_reftag == true
39
+ if key != nil
40
+ out += "<ref name=\"" + key.to_s + "\">"
41
+ else
42
+ out += "<ref>"
43
+ end
44
+ end
45
+ if type.to_s == "article"
46
+ out += "{{Cite article|"
47
+ elsif type.to_s == "book" || type.to_s == "booklet"
48
+ out += "{{Cite book|"
49
+ else
50
+ out += "{{Citation|"
51
+ end
52
+ out += props.to_a.map {|arr| arr.join("=") }.join("|")
53
+ out += "}}"
54
+ out += "</ref>" if with_reftag == true
55
+
56
+ return out
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bibtowiki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Morris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-04 00:00:00.000000000 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bibtex-ruby
17
+ requirement: &2168678540 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2168678540
26
+ description: Creates Wikipedia cirtations from BibTeX.
27
+ email: tom@tommorris.org
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/bibtowiki.rb
33
+ has_rdoc: true
34
+ homepage: http://github.com/tommorris/bibtowiki
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.6.2
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: BibTeX to Wikipedia.
58
+ test_files: []