citation 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a8c7aa9c394ffdb644be48a0fa90776834eda38
4
- data.tar.gz: 22e186c3ff80d1669d407c27f81abea2b2b431d4
3
+ metadata.gz: f2a8afb97fc644a93cd0304a13a88e1a80cf348b
4
+ data.tar.gz: 544201f296624df7b1dc1538222a485e21222643
5
5
  SHA512:
6
- metadata.gz: d9b83c79fc97e7357c234f349f05a9be5d6e17c471503be84ebd80378cc22bfec466efdf43875391c167b7b55479990dc6decf758a9337b1060d973b0e0c94ae
7
- data.tar.gz: 700489a43b29ddcc4726d1eab6c351c3deff177b3baebf7dd629a44c26d868c98998f3e966d1cf106088156fd7fb349d02eea536e9b62931f6d6b3b4eec73ce9
6
+ metadata.gz: 98fed2ac0f201b0ff770e8a3f0f548d4fe2366547ad8b1c1a0d75d37b341244f7f82ba509a3fa64e16a28b2fbfcc098b050e7024131f810a681e51f3b7b05ad9
7
+ data.tar.gz: 2e033505322ca312197f059cf6016b4d5c6d777b49afa826251e9afbb0bcd91aba05158e96fcf730dfabfd9890ecb6cc532679e889bd2daf0b928a93aa3e5daa
@@ -3,6 +3,9 @@ lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
3
3
  $:.unshift lib
4
4
  require 'uri'
5
5
  require 'time'
6
+ require 'rules/mla'
7
+ require 'rules/apa'
8
+ require 'rules/iso'
6
9
 
7
10
  module Citation
8
11
  class Base
@@ -31,7 +34,6 @@ module Citation
31
34
  when 'ISO'
32
35
  str = "#{@author} #{@title} #{@desc}, #{@year}."
33
36
  when 'bibtex'
34
-
35
37
  str = "@article{#{@author.gsub(' ','').gsub(/( |\.|,)/,'').downcase[0..5]}#{@year}#{@title.split.select{|i| i.length >3 }[0].downcase},
36
38
  title={#{@title}},
37
39
  author={#{@author.gsub(', and ',', ')}},
@@ -53,7 +55,7 @@ module Citation
53
55
  base.url = urls
54
56
 
55
57
  # fetch square bracket
56
- bracket_matcher = string.match(/\[([\w\d_ ]).+\]/)
58
+ bracket_matcher = string.match(/\[([a-zA-Z0-9_ ]).+\]/)
57
59
  base.sq = bracket_matcher[0] unless bracket_matcher.nil?
58
60
  string.slice!(base.sq)
59
61
 
@@ -66,59 +68,28 @@ module Citation
66
68
  string.slice!(base.year)
67
69
 
68
70
  # fetch title if format is MLA
69
- title_matcher = string.match(/".+"/)
70
- unless title_matcher.nil?
71
- base.title = title_matcher[0] unless title_matcher.nil?
72
- s = string.split(base.title)
73
- string.slice!(base.title)
74
- string.slice!('()')
75
- base.title.gsub!('"','')
76
-
77
- author = s.shift
78
- base.author = author
79
- base.desc = s.shift
80
- base.type = 'MLA'.to_sym
81
-
82
- string.slice!(base.author)
83
- string.slice!(base.desc)
71
+ if MLA.satisfy?(string, base)
72
+ string, base.title, base.author, base.desc, base.type = MLA.fetch(string, base)
84
73
  end
85
74
 
86
- # fetch title if format is APA
87
- title_matcher = string.match(/\(\)\. .+\. /)
88
- if base.type.empty? and not title_matcher.nil?
89
- base.title = title_matcher[0] unless title_matcher.nil?
90
- base.title.gsub!(/"|\(\)\. /,'')
91
-
92
- string.slice!(base.title)
93
- s = string.split('(). ')
94
- author = s.shift
95
- base.author = author
96
- base.desc = s.shift
97
- base.type = 'APA'.to_sym
98
- string.slice!(base.author)
99
- string.slice!(base.desc)
75
+ if APA.satisfy?(string, base)
76
+ string, base.title, base.author, base.desc, base.type = APA.fetch(string, base)
100
77
  end
101
78
 
102
79
 
103
- # fetch title if format is ISO 690
104
- iso_matcher = string.match(/, \.$/)
105
- if base.type.empty? and not iso_matcher.nil?
106
- s = string.gsub(/ ([A-Z]). /,'_\1_ ')
107
- arr = s.split('. ')
108
- base.author = arr.shift.gsub(/_([A-Z])_ /,' \1. ')
109
- base.title = arr.shift if base.title == ''
110
- base.desc = arr.shift
111
- base.type = 'ISO 6900'.to_sym
80
+ if ISO.satisfy?(string, base)
81
+ string, base.title, base.author, base.desc, base.type = ISO.fetch(string, base)
112
82
  end
113
83
 
114
84
 
115
85
  # fetch other
116
86
  if base.type.empty?
117
- s = string.gsub(/ ([A-Z]). /,'_\1_ ')
87
+ s = string.gsub(/ ([A-Z]).,{0,1} /,'_\1_ ')
88
+ s.gsub!('()','')
118
89
  arr = s.split('. ')
119
90
  base.author = arr.shift.gsub(/_([A-Z])_ /,' \1. ')
120
- base.title = arr.shift if base.title == ''
121
- base.desc = arr
91
+ base.title = arr.shift if base.title == '' or base.title.nil?
92
+ base.desc = arr.join(' ')
122
93
  end
123
94
  return base
124
95
 
@@ -128,20 +99,20 @@ end
128
99
 
129
100
  if __FILE__ == $0
130
101
  test = '[B ́at09] Norbert B ́atfai. On the Running Time of the Shortest Programs. CoRR, abs/0908.1159, 2009. http://arxiv.org/abs/0908.1159.'
131
- puts Citation.parse(test, false)
102
+ p Citation.parse(test, false)
132
103
  # MLA
133
104
  test = 'Bátfai, Norbert. "A disembodied developmental robotic agent called Samu B\'atfai." arXiv preprint arXiv:1511.02889 (2015).'
134
- puts Citation.parse(test, false)
105
+ p Citation.parse(test, false)
135
106
 
136
107
  # APA
137
108
  test = 'Bátfai, N. (2015). A disembodied developmental robotic agent called Samu B\'atfai. arXiv preprint arXiv:1511.02889.'
138
- puts Citation.parse(test, false)
109
+ p Citation.parse(test, false)
139
110
 
140
111
  # ISO 690
141
112
  test = 'BÁTFAI, Norbert. A disembodied developmental robotic agent called Samu B\'atfai. arXiv preprint arXiv:1511.02889, 2015.'
142
- puts Citation.parse(test, false)
113
+ p Citation.parse(test, false)
143
114
  test = 'MacKay, D. J. C., & Peto, L. C. B. (1995). A hierarchical Dirichlet language model. Natural Language Engineer- ing, 1, 289–307.'
144
- puts Citation.parse(test, false)
115
+ p Citation.parse(test, false)
145
116
  test = '[20] Y. Teh, M. Jordan, M. Beal, and D. Blei. Hierarchical Dirichlet processes. Journal of the American Statistical Association, 101(476):1566–1581, 2007.'
146
- puts Citation.parse(test,false).out('bibtex')
117
+ p Citation.parse(test,false).out('bibtex')
147
118
  end
@@ -0,0 +1,26 @@
1
+
2
+ require 'pathname'
3
+ lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
4
+ $:.unshift lib
5
+ require 'base'
6
+
7
+ class APA < RuleBase
8
+ def self.satisfy?(string, base)
9
+ @matcher = string.match(/\(\)\. .+\. /)
10
+ base.type.empty? and not @matcher.nil?
11
+ end
12
+
13
+ def self.fetch(string, base)
14
+ title = @matcher[0] unless @matcher.nil?
15
+ title.gsub!(/"|\(\)\. /,'')
16
+ string.slice!(title)
17
+
18
+ s = string.split('(). ')
19
+ author = s.shift
20
+ desc = s.shift
21
+ type = 'APA'.to_sym
22
+ string.slice!(author) unless string.empty?
23
+ string.slice!(desc) unless string.empty?
24
+ return string, title, author, desc, type
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+
2
+ class RuleBase
3
+ attr_reader :matcher
4
+ def self.satisfy?(string, base)
5
+
6
+ end
7
+
8
+ def self.fetch(string, base)
9
+
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require 'pathname'
2
+ lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
3
+ $:.unshift lib
4
+ require 'base'
5
+
6
+ class ISO < RuleBase
7
+ def self.satisfy?(string, base)
8
+ @matcher = string.match(/, \.$/)
9
+ base.type.empty? and not @matcher.nil?
10
+ end
11
+
12
+ def self.fetch(string, base)
13
+ s = string.gsub(/ ([A-Z]). /,'_\1_ ')
14
+ string.gsub!('()','')
15
+ arr = s.split('. ')
16
+ author = arr.shift.gsub(/_([A-Z])_ /,' \1. ')
17
+ title = arr.shift if title == '' or title.nil?
18
+ desc = arr.shift
19
+ type = 'ISO 6900'.to_sym
20
+ return string, title, author, desc, type
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ require 'pathname'
2
+ lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
3
+ $:.unshift lib
4
+ require 'base'
5
+
6
+ class MLA < RuleBase
7
+ def self.satisfy?(string, base)
8
+ @matcher = string.match(/".+"/)
9
+ !@matcher.nil?
10
+ end
11
+
12
+ def self.fetch(string, base)
13
+ title = @matcher[0]
14
+ string.slice!('()')
15
+ s = string.split(title)
16
+ string.slice!(title)
17
+ title.gsub!('"','')
18
+
19
+ author = s.shift
20
+ desc = s.shift
21
+ type = 'MLA'.to_sym
22
+ string.slice!(author) unless string.empty?
23
+ string.slice!(desc) unless string.empty?
24
+ return string, title, author, desc, type
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Citation
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Nishimura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-11 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,6 +93,10 @@ files:
93
93
  - lib/citation.rb
94
94
  - lib/citation/citation.rb
95
95
  - lib/citation/entrypoint.rb
96
+ - lib/citation/rules/apa.rb
97
+ - lib/citation/rules/base.rb
98
+ - lib/citation/rules/iso.rb
99
+ - lib/citation/rules/mla.rb
96
100
  - lib/citation/version.rb
97
101
  homepage: https://github.com/nishimuuu/citation
98
102
  licenses: