bibliography 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bibliography.gemspec +24 -0
- data/lib/bibliography.rb +12 -0
- data/lib/bibliography/bic.rb +5 -0
- data/lib/bibliography/bic/data/subjects.csv +2687 -0
- data/lib/bibliography/bic/subject.rb +58 -0
- data/lib/bibliography/version.rb +3 -0
- data/spec/bibliography/bic/subject_spec.rb +107 -0
- data/spec/bibliography_spec.rb +13 -0
- data/spec/spec_helper.rb +7 -0
- metadata +104 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'csv'
|
|
2
|
+
|
|
3
|
+
module Bibliography
|
|
4
|
+
module BIC
|
|
5
|
+
class Subject
|
|
6
|
+
Data = {}
|
|
7
|
+
CSV.foreach(File.join(File.dirname(__FILE__), 'data', 'subjects.csv')) do |line|
|
|
8
|
+
Data[line[0]] = {
|
|
9
|
+
code: line[0],
|
|
10
|
+
description: line[1]
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Class methods
|
|
15
|
+
def self.all
|
|
16
|
+
Data.keys.map {|s| Subject.new(s) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Instance methods
|
|
20
|
+
|
|
21
|
+
def initialize(code)
|
|
22
|
+
@data = Data[code] || {}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def code
|
|
26
|
+
@data[:code]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def description
|
|
30
|
+
@data[:description]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def valid?
|
|
34
|
+
!@data.empty?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def children?
|
|
38
|
+
!children.empty?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def children
|
|
42
|
+
return [] unless valid?
|
|
43
|
+
len = code.length
|
|
44
|
+
@children ||= Data.keys.select{ |key|
|
|
45
|
+
key.length > len && key[0..len-1] == code
|
|
46
|
+
}.map {|s| Subject.new(s) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def parent?
|
|
50
|
+
!parent.nil? && parent.valid?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def parent
|
|
54
|
+
@parent ||= Subject.new(code[0]) if valid? && code.length > 1
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bibliography::BIC::Subject do
|
|
4
|
+
context "Class" do
|
|
5
|
+
describe ".all" do
|
|
6
|
+
it "is an array of all subjects" do
|
|
7
|
+
all = described_class.all
|
|
8
|
+
expect(all).to have(described_class::Data.length).items
|
|
9
|
+
expect(all.first.code).to eq("A")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "Instance" do
|
|
15
|
+
context "valid" do
|
|
16
|
+
let(:subject) { Bibliography.subjects.new("AB") }
|
|
17
|
+
|
|
18
|
+
describe ".description" do
|
|
19
|
+
it "is a string" do
|
|
20
|
+
expect(subject.description).to eq("The arts: general issues")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe ".code" do
|
|
25
|
+
it "is a string, matching the original code" do
|
|
26
|
+
expect(subject.code).to eq("AB")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe ".valid?" do
|
|
31
|
+
it "is true" do
|
|
32
|
+
expect(subject.valid?).to be_true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe ".children?" do
|
|
37
|
+
it "is true" do
|
|
38
|
+
expect(subject.children?).to be_true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe ".children" do
|
|
43
|
+
it "returns an array of child subjects" do
|
|
44
|
+
expect(subject.children).to have(4).items
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe ".parent?" do
|
|
49
|
+
it "is true" do
|
|
50
|
+
expect(subject.parent?).to be_true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe ".parent" do
|
|
55
|
+
it "returns the parent Subject" do
|
|
56
|
+
expect(subject.parent.code).to eq("A")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "invalid" do
|
|
62
|
+
let(:subject) { Bibliography.subjects.new("invalid key") }
|
|
63
|
+
|
|
64
|
+
describe ".description" do
|
|
65
|
+
it "is nil" do
|
|
66
|
+
expect(subject.description).to be_nil
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe ".code" do
|
|
71
|
+
it "is a string matching the original code" do
|
|
72
|
+
expect(subject.code).to be_nil
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe ".valid?" do
|
|
77
|
+
it "is false" do
|
|
78
|
+
expect(subject.valid?).to be_false
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe ".children?" do
|
|
83
|
+
it "is false" do
|
|
84
|
+
expect(subject.children?).to be_false
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe ".children" do
|
|
89
|
+
it "is an empty array" do
|
|
90
|
+
expect(subject.children).to be_empty
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe ".parent?" do
|
|
95
|
+
it "is false" do
|
|
96
|
+
expect(subject.parent?).to be_false
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe ".parent" do
|
|
101
|
+
it "is nil" do
|
|
102
|
+
expect(subject.parent).to be_nil
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bibliography do
|
|
4
|
+
describe ".subjects" do
|
|
5
|
+
it "accepts a standards body name" do
|
|
6
|
+
expect(Bibliography.subjects(:bic)).to eq(Bibliography::BIC::Subject)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "defaults to BIC::Subject" do
|
|
10
|
+
expect(Bibliography.subjects).to eq(Bibliography::BIC::Subject)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bibliography
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Mike Robinson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: A library of useful tools for books and related standards
|
|
56
|
+
email:
|
|
57
|
+
- mike@studiolift.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- .rspec
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- bibliography.gemspec
|
|
69
|
+
- lib/bibliography.rb
|
|
70
|
+
- lib/bibliography/bic.rb
|
|
71
|
+
- lib/bibliography/bic/data/subjects.csv
|
|
72
|
+
- lib/bibliography/bic/subject.rb
|
|
73
|
+
- lib/bibliography/version.rb
|
|
74
|
+
- spec/bibliography/bic/subject_spec.rb
|
|
75
|
+
- spec/bibliography_spec.rb
|
|
76
|
+
- spec/spec_helper.rb
|
|
77
|
+
homepage: http://github.com/studiolift/bibliography
|
|
78
|
+
licenses:
|
|
79
|
+
- MIT
|
|
80
|
+
metadata: {}
|
|
81
|
+
post_install_message:
|
|
82
|
+
rdoc_options: []
|
|
83
|
+
require_paths:
|
|
84
|
+
- lib
|
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - '>='
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
requirements: []
|
|
96
|
+
rubyforge_project:
|
|
97
|
+
rubygems_version: 2.1.0
|
|
98
|
+
signing_key:
|
|
99
|
+
specification_version: 4
|
|
100
|
+
summary: Currently only offers an interface to BIC subjects
|
|
101
|
+
test_files:
|
|
102
|
+
- spec/bibliography/bic/subject_spec.rb
|
|
103
|
+
- spec/bibliography_spec.rb
|
|
104
|
+
- spec/spec_helper.rb
|