scholar 0.1.1 → 0.1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/Gemfile +3 -0
- data/Gemfile.lock +54 -24
- data/README.md +14 -14
- data/lib/scholar.rb +0 -2
- data/lib/scholar/citation.rb +8 -5
- data/lib/scholar/search.rb +15 -0
- data/lib/scholar/utilities/contributor.rb +2 -0
- data/scholar.gemspec +2 -2
- data/spec/factories/contributor.rb +1 -1
- data/spec/scholar/citation_spec.rb +44 -0
- data/spec/scholar/search_spec.rb +9 -4
- data/spec/scholar/utilities/contributor_spec.rb +2 -2
- data/spec/spec_helper.rb +10 -0
- metadata +11 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a90a3bff79b16dfad4e4bc5bc09406a5f2e152bc
|
4
|
+
data.tar.gz: fbf2f945a7ac9972cc10e0d28fcaa15e24e36143
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21f72e1dbc403101ab21360ede3b307a71ed95ca77602e86b30200755b0c570140bfd6f8ff6efe10d4c0ccb16b54ec1671143dd1ba79760f897f49b3a2d3feb2
|
7
|
+
data.tar.gz: f616eb866b88c827380d1b88722d502b53310a0dbf6ec1b8e5ef57932a760e7f2465c941bec2eb8b15ba9d08bb79155eec83364776b7c5ba841b83ede6cceba5
|
data/.rspec
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0-p247
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,50 +1,67 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
scholar (0.1.1)
|
5
|
-
activesupport (~>
|
4
|
+
scholar (0.1.1.1)
|
5
|
+
activesupport (~> 4.0.0)
|
6
6
|
faraday (~> 0.8.7)
|
7
7
|
faraday_middleware (~> 0.9.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (
|
13
|
-
i18n (~> 0.6)
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
activesupport (4.0.0)
|
13
|
+
i18n (~> 0.6, >= 0.6.4)
|
14
|
+
minitest (~> 4.2)
|
15
|
+
multi_json (~> 1.3)
|
16
|
+
thread_safe (~> 0.1)
|
17
|
+
tzinfo (~> 0.3.37)
|
18
|
+
addressable (2.3.5)
|
19
|
+
atomic (1.1.14)
|
20
|
+
atomic (1.1.14-java)
|
21
|
+
cane (2.6.0)
|
17
22
|
parallel
|
18
|
-
coderay (1.0.
|
19
|
-
|
23
|
+
coderay (1.0.9)
|
24
|
+
colorize (0.6.0)
|
25
|
+
coveralls (0.6.3)
|
26
|
+
colorize
|
27
|
+
multi_json (~> 1.3)
|
28
|
+
rest-client
|
29
|
+
simplecov (>= 0.7)
|
30
|
+
thor
|
31
|
+
crack (0.4.1)
|
32
|
+
safe_yaml (~> 0.9.0)
|
20
33
|
diff-lcs (1.1.3)
|
21
34
|
factory_girl (4.2.0)
|
22
35
|
activesupport (>= 3.0.0)
|
23
|
-
faraday (0.8.
|
24
|
-
multipart-post (~> 1.
|
36
|
+
faraday (0.8.8)
|
37
|
+
multipart-post (~> 1.2.0)
|
25
38
|
faraday_middleware (0.9.0)
|
26
39
|
faraday (>= 0.7.4, < 0.9)
|
27
|
-
ffi (1.
|
28
|
-
fuubar (1.1.
|
40
|
+
ffi (1.9.0-java)
|
41
|
+
fuubar (1.1.1)
|
29
42
|
rspec (~> 2.0)
|
30
43
|
rspec-instafail (~> 0.2.0)
|
31
|
-
ruby-progressbar (~> 1.0
|
32
|
-
i18n (0.6.
|
44
|
+
ruby-progressbar (~> 1.0)
|
45
|
+
i18n (0.6.5)
|
33
46
|
log_buddy (0.7.0)
|
34
|
-
method_source (0.8.
|
35
|
-
|
47
|
+
method_source (0.8.2)
|
48
|
+
mime-types (1.25)
|
49
|
+
minitest (4.7.5)
|
50
|
+
multi_json (1.8.2)
|
36
51
|
multipart-post (1.2.0)
|
37
|
-
parallel (0.
|
38
|
-
pry (0.9.
|
52
|
+
parallel (0.9.0)
|
53
|
+
pry (0.9.12.2)
|
39
54
|
coderay (~> 1.0.5)
|
40
55
|
method_source (~> 0.8)
|
41
56
|
slop (~> 3.4)
|
42
|
-
pry (0.9.
|
57
|
+
pry (0.9.12.2-java)
|
43
58
|
coderay (~> 1.0.5)
|
44
59
|
method_source (~> 0.8)
|
45
60
|
slop (~> 3.4)
|
46
61
|
spoon (~> 0.0)
|
47
|
-
rake (10.0
|
62
|
+
rake (10.1.0)
|
63
|
+
rest-client (1.6.7)
|
64
|
+
mime-types (>= 1.16)
|
48
65
|
rspec (2.12.0)
|
49
66
|
rspec-core (~> 2.12.0)
|
50
67
|
rspec-expectations (~> 2.12.0)
|
@@ -54,11 +71,22 @@ GEM
|
|
54
71
|
diff-lcs (~> 1.1.3)
|
55
72
|
rspec-instafail (0.2.4)
|
56
73
|
rspec-mocks (2.12.2)
|
57
|
-
ruby-progressbar (1.0
|
58
|
-
|
59
|
-
|
74
|
+
ruby-progressbar (1.2.0)
|
75
|
+
safe_yaml (0.9.7)
|
76
|
+
simplecov (0.7.1)
|
77
|
+
multi_json (~> 1.0)
|
78
|
+
simplecov-html (~> 0.7.1)
|
79
|
+
simplecov-html (0.7.1)
|
80
|
+
slop (3.4.6)
|
81
|
+
spoon (0.0.4)
|
60
82
|
ffi
|
61
83
|
spork (0.9.2)
|
84
|
+
thor (0.18.1)
|
85
|
+
thread_safe (0.1.3)
|
86
|
+
atomic
|
87
|
+
thread_safe (0.1.3-java)
|
88
|
+
atomic
|
89
|
+
tzinfo (0.3.38)
|
62
90
|
vcr (2.4.0)
|
63
91
|
webmock (1.8.11)
|
64
92
|
addressable (>= 2.2.7)
|
@@ -70,6 +98,7 @@ PLATFORMS
|
|
70
98
|
|
71
99
|
DEPENDENCIES
|
72
100
|
cane
|
101
|
+
coveralls (= 0.6.3)
|
73
102
|
factory_girl (~> 4.2.0)
|
74
103
|
fuubar (~> 1.1.0)
|
75
104
|
log_buddy (~> 0.7.0)
|
@@ -77,6 +106,7 @@ DEPENDENCIES
|
|
77
106
|
rake (~> 10.0)
|
78
107
|
rspec (~> 2.12.0)
|
79
108
|
scholar!
|
109
|
+
simplecov (= 0.7.1)
|
80
110
|
spork (~> 0.9.2)
|
81
111
|
vcr (~> 2.4.0)
|
82
112
|
webmock (~> 1.8.0)
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Scholar
|
1
|
+
# Scholar
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/scholar.png)](https://rubygems.org/gems/scholar) [![Build Status](https://secure.travis-ci.org/noted/scholar.png)](https://travis-ci.org/noted/scholar) [![Code Climate](https://codeclimate.com/github/noted/scholar.png)](https://codeclimate.com/github/noted/scholar) [![Coverage Status](https://coveralls.io/repos/noted/scholar/badge.png?branch=master)](https://coveralls.io/r/noted/scholar)
|
2
4
|
|
3
5
|
Scholar is a Ruby library for building [MLA citations](http://www.mla.org/) for scholarly works. Just pass Scholar your data and it'll do the rest.
|
4
6
|
|
@@ -50,9 +52,9 @@ salinger.html # => Salinger, J. D. <em>Catcher in the Rye</em>. Boston: Little,
|
|
50
52
|
|
51
53
|
`Scholar::Citation.new` only takes a `Hash` with the attributes associated with the source.
|
52
54
|
|
53
|
-
|
55
|
+
#### Required Keys
|
54
56
|
|
55
|
-
|
57
|
+
##### Global Attributes
|
56
58
|
|
57
59
|
All source types can (and must) take these fields.
|
58
60
|
|
@@ -61,7 +63,7 @@ Key | Description
|
|
61
63
|
`:type` | The type of publication you're citing ([see the wiki for a list of supported types](types)). Must be a `Symbol` object.
|
62
64
|
`:contributors` | An array of contributors (see below for details). If there are no contributors, pass an empty `Array`.
|
63
65
|
|
64
|
-
|
66
|
+
###### Contributors
|
65
67
|
|
66
68
|
The `:contributors` key is an array of hashes that define contributors. Here's an example.
|
67
69
|
|
@@ -107,10 +109,6 @@ Key | Description
|
|
107
109
|
`:last` | The contributor's last name (surname).
|
108
110
|
`:suffix` | Any suffixes or titles the contributor has ("PhD", "Esq", "Jr", "KBD", et cetera). Omit any periods.
|
109
111
|
|
110
|
-
## Supported Ruby Versions
|
111
|
-
|
112
|
-
Scholar is tested on MRI version 1.9.2, 1.9.3, and 2.0.0.
|
113
|
-
|
114
112
|
### Search
|
115
113
|
|
116
114
|
```ruby
|
@@ -118,17 +116,19 @@ search = Scholar::Search.new("harry potter")
|
|
118
116
|
search.results # => [#<Scholar::Citation>, #<Scholar::Citation>, ...]
|
119
117
|
```
|
120
118
|
|
119
|
+
## Supported Ruby Versions
|
120
|
+
|
121
|
+
Scholar is tested on MRI versions 1.9.2, 1.9.3, and 2.0.0, JRuby 1.7.3, and Rubinius 2.0.0.
|
122
|
+
|
121
123
|
## Contributing
|
122
124
|
|
123
125
|
1. [Fork the repository.][fork]
|
124
126
|
2. [Create a topic branch.][branch]
|
125
127
|
3. Add tests for your unimplemented feature or bug fix.
|
126
|
-
4.
|
127
|
-
5.
|
128
|
-
6.
|
129
|
-
7.
|
130
|
-
8. Add, commit, and push your changes.
|
131
|
-
9. [Submit a pull request.][pr]
|
128
|
+
4. Write code until all tests (ran with `bundle exec rspec`) passes.
|
129
|
+
5. Add documentation for your feature or bug fix.
|
130
|
+
6. Add, commit, and push your changes.
|
131
|
+
7. [Submit a pull request.][pr]
|
132
132
|
|
133
133
|
[types]: https://github.com/noted/scholar/wiki/Supported-Types
|
134
134
|
[fork]: http://help.github.com/fork-a-repo/
|
data/lib/scholar.rb
CHANGED
data/lib/scholar/citation.rb
CHANGED
@@ -47,6 +47,14 @@ module Scholar
|
|
47
47
|
@raw = @attributes.clone
|
48
48
|
@attributes.delete(:type)
|
49
49
|
|
50
|
+
@attributes.each do |k, v|
|
51
|
+
if v.is_a?(Fixnum)
|
52
|
+
@attributes[k] = v.to_s
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@attributes.delete_if {|k, v| v.nil? || v.empty? }
|
57
|
+
|
50
58
|
if @attributes[:contributors]
|
51
59
|
@attributes = Scholar::Utilities.contributors!(@attributes)
|
52
60
|
end
|
@@ -69,10 +77,5 @@ module Scholar
|
|
69
77
|
|
70
78
|
hash
|
71
79
|
end
|
72
|
-
|
73
|
-
# Returns the Citation object in JSON form.
|
74
|
-
def to_json
|
75
|
-
hash = self.to_hash.to_json
|
76
|
-
end
|
77
80
|
end
|
78
81
|
end
|
data/lib/scholar/search.rb
CHANGED
@@ -35,6 +35,21 @@ module Scholar
|
|
35
35
|
self
|
36
36
|
end
|
37
37
|
|
38
|
+
# Return as hash.
|
39
|
+
def to_hash
|
40
|
+
hash = {}
|
41
|
+
|
42
|
+
instance_variables.each do |v|
|
43
|
+
hash[v.to_s[1..-1].to_sym] = instance_variable_get(v)
|
44
|
+
end
|
45
|
+
|
46
|
+
hash[:results].each do |c|
|
47
|
+
hash[:results][hash[:results].index(c)] = c.to_hash
|
48
|
+
end
|
49
|
+
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
38
53
|
private
|
39
54
|
|
40
55
|
def perform!(query)
|
data/scholar.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "scholar"
|
8
|
-
gem.version = "0.1.1"
|
8
|
+
gem.version = "0.1.1.1"
|
9
9
|
gem.authors = ["Ethan Turkeltaub"]
|
10
10
|
gem.email = ["ethan.turkeltaub@gmail.com"]
|
11
11
|
gem.description = %q{Generate valid MLA citations.}
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_dependency 'activesupport', '~>
|
21
|
+
gem.add_dependency 'activesupport', '~> 4.0.0'
|
22
22
|
gem.add_dependency 'faraday', '~> 0.8.7'
|
23
23
|
gem.add_dependency 'faraday_middleware', '~> 0.9.0'
|
24
24
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Scholar::Citation do
|
4
|
+
let(:c) do
|
5
|
+
Scholar::Citation.new({
|
6
|
+
:type => :book,
|
7
|
+
:media => :print,
|
8
|
+
:title => "The Hitchhiker's Guide to the Galaxy",
|
9
|
+
:contributors => [
|
10
|
+
{
|
11
|
+
:role => :author,
|
12
|
+
:first => "Douglas",
|
13
|
+
:middle => "Noel",
|
14
|
+
:last => "Adams"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
:role => :editor,
|
18
|
+
:first => "Peter",
|
19
|
+
:last => "Guzzardi"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
:role => :translator,
|
23
|
+
:first => "Les",
|
24
|
+
:last => "Grossman"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
:role => :compiler,
|
28
|
+
:first => "Eion",
|
29
|
+
:last => "Colfer"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
:edition => 1,
|
33
|
+
:volume => 1,
|
34
|
+
:publisher => "Random House",
|
35
|
+
:city => "London",
|
36
|
+
:year => "1972",
|
37
|
+
:series => "The Hitchhiker's Guide to the Galaxy"
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#to_hash" do
|
42
|
+
it { c.to_hash.keys.should =~ [:attributes, :raw, :html] }
|
43
|
+
end
|
44
|
+
end
|
data/spec/scholar/search_spec.rb
CHANGED
@@ -5,16 +5,21 @@ describe Scholar::Search do
|
|
5
5
|
VCR.insert_cassette 'search', :record => :all
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
let(:search) do
|
9
|
+
Scholar::Search.new("foobar")
|
10
|
+
end
|
12
11
|
|
12
|
+
describe ".new" do
|
13
13
|
it { search.query.should eql "foobar" }
|
14
14
|
it { search.results.should be_an_instance_of Array }
|
15
15
|
it { search.results[0].should be_an_instance_of Scholar::Citation }
|
16
16
|
end
|
17
17
|
|
18
|
+
describe "#to_hash" do
|
19
|
+
it { search.to_hash.keys.should =~ [:query, :results] }
|
20
|
+
it { search.to_hash[:results][0].should be_an_instance_of Hash }
|
21
|
+
end
|
22
|
+
|
18
23
|
after do
|
19
24
|
VCR.eject_cassette
|
20
25
|
end
|
@@ -5,7 +5,7 @@ describe Scholar::Utilities::Contributor do
|
|
5
5
|
let(:c) { build(:contributor, :last) }
|
6
6
|
|
7
7
|
it { c.should be_an_instance_of Scholar::Utilities::Contributor }
|
8
|
-
it { c.name.should eql "Grossman,
|
8
|
+
it { c.name.should eql "Grossman, L. R., Esq" }
|
9
9
|
end
|
10
10
|
|
11
11
|
context "non-author" do
|
@@ -25,6 +25,6 @@ describe Scholar::Utilities::Contributor do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it { first.name.should eql "Sample, John Q., PhD" }
|
28
|
-
it { last.name.should eql "
|
28
|
+
it { last.name.should eql "L. R. Grossman, Esq" }
|
29
29
|
end
|
30
30
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scholar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ethan Turkeltaub
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 4.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 4.0.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: faraday
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: faraday_middleware
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -88,6 +81,7 @@ files:
|
|
88
81
|
- scholar.gemspec
|
89
82
|
- spec/factories/contributor.rb
|
90
83
|
- spec/factories/contributor_list.rb
|
84
|
+
- spec/scholar/citation_spec.rb
|
91
85
|
- spec/scholar/search_spec.rb
|
92
86
|
- spec/scholar/source_spec.rb
|
93
87
|
- spec/scholar/sources/book_spec.rb
|
@@ -99,37 +93,31 @@ files:
|
|
99
93
|
homepage: http://github.com/noted/scholar
|
100
94
|
licenses:
|
101
95
|
- MIT
|
96
|
+
metadata: {}
|
102
97
|
post_install_message:
|
103
98
|
rdoc_options: []
|
104
99
|
require_paths:
|
105
100
|
- lib
|
106
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
102
|
requirements:
|
109
|
-
- -
|
103
|
+
- - '>='
|
110
104
|
- !ruby/object:Gem::Version
|
111
105
|
version: '0'
|
112
|
-
segments:
|
113
|
-
- 0
|
114
|
-
hash: 1067264813
|
115
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
107
|
requirements:
|
118
|
-
- -
|
108
|
+
- - '>='
|
119
109
|
- !ruby/object:Gem::Version
|
120
110
|
version: '0'
|
121
|
-
segments:
|
122
|
-
- 0
|
123
|
-
hash: 1067264813
|
124
111
|
requirements: []
|
125
112
|
rubyforge_project:
|
126
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 2.1.3
|
127
114
|
signing_key:
|
128
|
-
specification_version:
|
115
|
+
specification_version: 4
|
129
116
|
summary: Generate valid MLA citations.
|
130
117
|
test_files:
|
131
118
|
- spec/factories/contributor.rb
|
132
119
|
- spec/factories/contributor_list.rb
|
120
|
+
- spec/scholar/citation_spec.rb
|
133
121
|
- spec/scholar/search_spec.rb
|
134
122
|
- spec/scholar/source_spec.rb
|
135
123
|
- spec/scholar/sources/book_spec.rb
|