frbr 0.1.0
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.
- data/LICENSE +21 -0
- data/README +47 -0
- data/lib/frbr/concept.rb +11 -0
- data/lib/frbr/corporate_body.rb +12 -0
- data/lib/frbr/event.rb +11 -0
- data/lib/frbr/expression.rb +105 -0
- data/lib/frbr/family.rb +12 -0
- data/lib/frbr/groups.rb +204 -0
- data/lib/frbr/item.rb +88 -0
- data/lib/frbr/manifestation.rb +106 -0
- data/lib/frbr/object.rb +11 -0
- data/lib/frbr/person.rb +12 -0
- data/lib/frbr/place.rb +11 -0
- data/lib/frbr/work.rb +86 -0
- data/lib/frbr.rb +21 -0
- metadata +82 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Ross Singer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
A very basic representation of the FRBR Group 1, 2, and 3 entities and the relationships between them.
|
2
|
+
|
3
|
+
This library is not intended to provide the actual bibliographic attributes of the entities, just establish model and the relationships.
|
4
|
+
|
5
|
+
Everything is defined as a Module that you would mixin into some other object.
|
6
|
+
|
7
|
+
A basic example:
|
8
|
+
|
9
|
+
# Set up our bibliographic objects that we want to FRBR-ize
|
10
|
+
class Story
|
11
|
+
attr_accessor :title
|
12
|
+
end
|
13
|
+
|
14
|
+
class Book
|
15
|
+
attr_accessor :language, format
|
16
|
+
end
|
17
|
+
|
18
|
+
class BookEdition
|
19
|
+
attr_accessor :isbn, :date_published
|
20
|
+
end
|
21
|
+
|
22
|
+
class Person
|
23
|
+
attr_accessor :name
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
story = Story.new
|
28
|
+
story.title = "The Old Man and the Sea"
|
29
|
+
story.extend(FRBR::Work) # these modules could also be included directly in the class
|
30
|
+
|
31
|
+
person = Person.new
|
32
|
+
person.name = "Ernest Hemingway"
|
33
|
+
person.extend(FRBR::Person)
|
34
|
+
story.add_creator(person) # or person.add_creation(story)
|
35
|
+
|
36
|
+
book = Book.new
|
37
|
+
book.language = 'English'
|
38
|
+
book.format = 'text'
|
39
|
+
book.extend(FRBR::Expression)
|
40
|
+
book.realization_of(story) # or story.add_realization(book)
|
41
|
+
|
42
|
+
edition = BookEdition.new
|
43
|
+
edition.isbn = '0099273969'
|
44
|
+
edition.date_published = '2000'
|
45
|
+
edition.extend(FRBR::Manifestation)
|
46
|
+
edition.embodiment_of(book) # or book.add_embodiment(edition)
|
47
|
+
|
data/lib/frbr/concept.rb
ADDED
data/lib/frbr/event.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
module FRBR
|
2
|
+
module Expression
|
3
|
+
include FRBR::Group1
|
4
|
+
include FRBR::Group3
|
5
|
+
attr_reader :realizers, :realization_of, :embodiments
|
6
|
+
|
7
|
+
alias :work :realization_of
|
8
|
+
alias :manifestations :embodiments
|
9
|
+
|
10
|
+
def is_realization_of(work)
|
11
|
+
raise ArgumentError, "Must be a realization of a work" unless work.is_a?(FRBR::Work)
|
12
|
+
@realization_of = work
|
13
|
+
work.add_realization(self) unless work.realizations && work.realizations.index(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :is_expression_of, :is_realization_of
|
17
|
+
|
18
|
+
def clear_realization_of
|
19
|
+
if @realization_of && !@realization_of.nil?
|
20
|
+
if @realization_of.realizations && @realization_of.realizations.index(self)
|
21
|
+
@realization_of.remove_realization(self)
|
22
|
+
end
|
23
|
+
@realization_of = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :clear_expression_of, :clear_realization_of
|
28
|
+
|
29
|
+
def add_realizer(realizer)
|
30
|
+
raise ArgumentError, "Realizer must be a Group 2 entity" unless realizer.is_a?(FRBR::Group2)
|
31
|
+
@realizers ||= []
|
32
|
+
@realizers << realizer unless @realizers.index(realizer)
|
33
|
+
realizer.add_realization(self) unless realizer.realizer_of?(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def remove_realizer(realizer)
|
37
|
+
@realizers.delete(realizer)
|
38
|
+
realizer.remove_realization(self) if realizer.realizer_of?(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def has_realizer?(agent)
|
42
|
+
return true if @realizers && @realizers.index(agent)
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_embodiment(manifestation)
|
47
|
+
raise ArgumentError, "Embodiments must be manifestations" unless manifestation.is_a?(FRBR::Manifestation)
|
48
|
+
@embodiments ||= []
|
49
|
+
@embodiments << manifestation unless @embodiments.index(manifestation)
|
50
|
+
manifestation.is_embodiment_of(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
alias_method :add_manifestation, :add_embodiment
|
54
|
+
|
55
|
+
def remove_embodiment(manifestation)
|
56
|
+
@embodiments.delete(manifestation) if @embodiments
|
57
|
+
manifestation.clear_embodiment_of
|
58
|
+
end
|
59
|
+
|
60
|
+
alias_method :remove_manifestation, :remove_embodiment
|
61
|
+
|
62
|
+
def add_related(expression)
|
63
|
+
(action, relationship) = this_method.split("_")
|
64
|
+
self.add_relationship_to_entity(expression, relationship.to_sym, FRBR::Expression, true)
|
65
|
+
end
|
66
|
+
|
67
|
+
def remove_related(expression)
|
68
|
+
(action, relationship) = this_method.split("_")
|
69
|
+
self.remove_relationship_from_entity(expression, relationship.to_sym, FRBR::Expression, true)
|
70
|
+
end
|
71
|
+
|
72
|
+
def equivalents
|
73
|
+
equivalents = []
|
74
|
+
if self.realization_of
|
75
|
+
self.realization_of.realizations.each do | expression |
|
76
|
+
next if expression == self
|
77
|
+
equivalents << expression
|
78
|
+
end
|
79
|
+
end
|
80
|
+
equivalents
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.valid_relationships
|
84
|
+
{:translation=>:translation_of, :revision=>:revision_of, :arrangement=>:arrangement_of, :derivative=>:based_on, :preceded_by=>:succeeded_by, :described_in=>:describes, :augmentation=>:augmentation_of, :contains=>:contained_in, :complemented_by=>:complements, :adaptation=>:adaptation_of, :imitation=>:imitation_of, :related=>:related}
|
85
|
+
end
|
86
|
+
private
|
87
|
+
def self.included(o)
|
88
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
89
|
+
add_method_aliases
|
90
|
+
end
|
91
|
+
def self.extended(o)
|
92
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
93
|
+
add_method_aliases
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.add_method_aliases
|
97
|
+
self.valid_relationships.to_a.flatten.each do |rel|
|
98
|
+
next if rel == :related
|
99
|
+
alias_method "add_#{rel}".to_sym, :add_related
|
100
|
+
alias_method "remove_#{rel}".to_sym, :remove_related
|
101
|
+
alias_method rel, :related
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/frbr/family.rb
ADDED
data/lib/frbr/groups.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
module FRBR
|
2
|
+
module Group1
|
3
|
+
attr_reader :relationships
|
4
|
+
def self.check_frbr_validity(o, mod_name)
|
5
|
+
raise TypeError, "Group 1 entities cannot also be Group 2 entities" if o.is_a?(FRBR::Group2)
|
6
|
+
unless mod_name == "FRBR::Group1"
|
7
|
+
entities = [FRBR::Work, FRBR::Expression, FRBR::Manifestation, FRBR::Item, FRBR::Concept, FRBR::Event, FRBR::Object, FRBR::Place]
|
8
|
+
entities.delete(Kernel.constant(mod_name))
|
9
|
+
entities.each do |e|
|
10
|
+
raise TypeError, "#{mod_name} cannot also be a #{e.to_s}" if o.is_a?(e)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
[FRBR::Concept, FRBR::Event, FRBR::Object, FRBR::Place].each do |subject|
|
14
|
+
raise TypeError, "#{subject} cannot be a Group 1 entity" if o.is_a?(subject)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def related
|
19
|
+
return @relationships[this_method.to_sym]
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def add_relationship_to_entity(entity, relationship, entity_type, reify)
|
24
|
+
unless entity_type.valid_relationships[relationship] || entity_type.valid_relationships.values.index(relationship)
|
25
|
+
raise ArgumentError, "relationship must be one of: #{entity_type.valid_relationships.to_a.flatten.join(", ")}"
|
26
|
+
end
|
27
|
+
raise ArgumentError, "Relationship must be to another #{entity_type}" unless entity.is_a?(entity_type)
|
28
|
+
@relationships ||={}
|
29
|
+
@relationships[relationship] ||= []
|
30
|
+
@relationships[relationship] << entity unless @relationships[relationship].index(entity)
|
31
|
+
if reify
|
32
|
+
if entity_type.valid_relationships[relationship]
|
33
|
+
entity.add_relationship_to_entity(self, entity_type.valid_relationships[relationship], entity_type, false)
|
34
|
+
else
|
35
|
+
entity.add_relationship_to_entity(self, entity_type.valid_relationships.invert[relationship], entity_type, false)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_relationship_from_entity(entity, relationship, entity_type, reify)
|
41
|
+
@relationships[relationship].delete(entity) if @relationships && @relationships[relationship]
|
42
|
+
if reify
|
43
|
+
if entity_type.valid_relationships[relationship]
|
44
|
+
entity.remove_relationship_from_entity(self, entity_type.valid_relationships[relationship], entity_type, false)
|
45
|
+
else
|
46
|
+
entity.remove_relationship_from_entity(self, entity_type.valid_relationships.invert[relationship], entity_type, false)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.extended(o)
|
52
|
+
self.check_frbr_validity(o, self.name)
|
53
|
+
end
|
54
|
+
|
55
|
+
def this_method
|
56
|
+
caller[0]=~/`(.*?)'/
|
57
|
+
$1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
module Group2
|
61
|
+
attr_reader :created, :realized, :produced, :owner_of, :related_agents
|
62
|
+
|
63
|
+
def self.check_frbr_validity(o, mod_name)
|
64
|
+
raise TypeError, "Group 2 entities cannot also be Group 1 entities" if o.is_a?(FRBR::Group1)
|
65
|
+
unless mod_name == "FRBR::Group2"
|
66
|
+
entities = [FRBR::Person, FRBR::CorporateBody, FRBR::Family, FRBR::Concept, FRBR::Event, FRBR::Object, FRBR::Place]
|
67
|
+
entities.delete(Kernel.constant(mod_name))
|
68
|
+
entities.each do |e|
|
69
|
+
raise TypeError, "#{mod_name} cannot also be a #{e.to_s}" if o.is_a?(e)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
[FRBR::Concept, FRBR::Event, FRBR::Object, FRBR::Place].each do |subject|
|
73
|
+
raise TypeError, "#{subject} cannot be a Group 2 entity" if o.is_a?(subject)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.extended(o)
|
78
|
+
self.check_frbr_validity(o, self.name)
|
79
|
+
end
|
80
|
+
|
81
|
+
def creator_of?(thing)
|
82
|
+
return true if @created && @created.index(thing)
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_creation(work)
|
87
|
+
raise ArgumentError, "Only Works can be created" unless work.is_a?(FRBR::Work)
|
88
|
+
@created ||=[]
|
89
|
+
@created << work unless @created.index(work)
|
90
|
+
work.add_creator(self) unless work.has_creator?(work)
|
91
|
+
end
|
92
|
+
|
93
|
+
def remove_creation(work)
|
94
|
+
@created.delete(work) if @created
|
95
|
+
work.creators.delete(self) if work.has_creator?(self)
|
96
|
+
end
|
97
|
+
|
98
|
+
def realizer_of?(thing)
|
99
|
+
return true if @realized && @realized.index(thing)
|
100
|
+
return false
|
101
|
+
end
|
102
|
+
|
103
|
+
def add_realization(expression)
|
104
|
+
raise ArgumentError, "Only Expressions can be realized" unless expression.is_a?(FRBR::Expression)
|
105
|
+
@realized ||=[]
|
106
|
+
@realized << expression unless @realized.index(expression)
|
107
|
+
expression.add_realizer(self) unless expression.has_realizer?(self)
|
108
|
+
end
|
109
|
+
|
110
|
+
def remove_realization(expression)
|
111
|
+
@realized.delete(expression) if @realized
|
112
|
+
expression.remove_realizer(self) if expression.has_realizer?(self)
|
113
|
+
end
|
114
|
+
|
115
|
+
def producer_of?(thing)
|
116
|
+
return true if @produced && @produced.index(thing)
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_production(manifestation)
|
121
|
+
raise ArgumentError, "Only Manifestations can be produced" unless manifestation.is_a?(FRBR::Manifestation)
|
122
|
+
@produced ||= []
|
123
|
+
@produced << manifestation unless @produced.index(manifestation)
|
124
|
+
manifestation.add_producer(self) unless manifestation.has_producer?(self)
|
125
|
+
end
|
126
|
+
|
127
|
+
def remove_production(manifestation)
|
128
|
+
@produced.delete(manifestation) if @produced
|
129
|
+
manifestation.remove_producer(self) if manifestation.has_producer?(self)
|
130
|
+
end
|
131
|
+
|
132
|
+
def owner_of?(thing)
|
133
|
+
return true if @owner_of && @owner_of.index(thing)
|
134
|
+
return false
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_ownership(item)
|
138
|
+
raise ArgumentError, "Only Items can be owned" unless item.is_a?(FRBR::Item)
|
139
|
+
@owner_of ||= []
|
140
|
+
@owner_of << item unless @owner_of.index(item)
|
141
|
+
item.add_owner(self) unless item.has_owner?(self)
|
142
|
+
end
|
143
|
+
|
144
|
+
def remove_ownership(item)
|
145
|
+
@owner_of.delete(item) if @owner_of
|
146
|
+
item.remove_owned_by(self) if item.has_owner?(self)
|
147
|
+
end
|
148
|
+
|
149
|
+
def add_related_agent(agent)
|
150
|
+
raise ArgumentError, "Related agents must be Group 2 entities" unless agent.is_a?(FRBR::Group2)
|
151
|
+
@related_agents ||=[]
|
152
|
+
@related_agents << agent unless @related_agents.index(agent)
|
153
|
+
agent.add_related_agent(self) unless agent.related_agents && agent.related_agents.index(self)
|
154
|
+
end
|
155
|
+
|
156
|
+
def remove_related_agent(agent)
|
157
|
+
@related_agents.delete(agent) if @related_agents
|
158
|
+
agent.remove_related_agent(self) if agent.related_agents && agent.related_agents.index(self)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
module Group3
|
162
|
+
attr_reader :subject_of, :related_subjects
|
163
|
+
|
164
|
+
def self.check_frbr_validity(o, mod_name)
|
165
|
+
|
166
|
+
unless mod_name == "FRBR::Group3"
|
167
|
+
entities = [FRBR::Work, FRBR::Expression, FRBR::Manifestation, FRBR::Item,
|
168
|
+
FRBR::Person, FRBR::CorporateBody, FRBR::Family,
|
169
|
+
FRBR::Concept, FRBR::Event, FRBR::Object, FRBR::Place]
|
170
|
+
entities.delete(Kernel.constant(mod_name))
|
171
|
+
entities.each do |e|
|
172
|
+
raise TypeError, "#{mod_name} cannot also be a #{e.to_s}" if o.is_a?(e)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def add_subject_of(work)
|
178
|
+
raise ArgumentError, "Group 3 entities can only be subjects of Works" unless work.is_a?(FRBR::Work)
|
179
|
+
@subject_of ||= []
|
180
|
+
@subject_of << work unless @subject_of.index(work)
|
181
|
+
work.add_subject(self) unless work.subjects && work.subjects.index(self)
|
182
|
+
end
|
183
|
+
|
184
|
+
def remove_subject_of(work)
|
185
|
+
return unless @subject_of
|
186
|
+
@subject_of.delete(work) if @subject_of && @subject_of.index(work)
|
187
|
+
work.remove_subject(self) if work.subjects && work.subjects.index(self)
|
188
|
+
end
|
189
|
+
|
190
|
+
def add_related_subject(thing)
|
191
|
+
raise ArgumentError, "Group 3 entities can only be related to other Group 3 entities" unless thing.is_a?(FRBR::Group3)
|
192
|
+
@related_subjects ||= []
|
193
|
+
@related_subjects << thing unless @related_subjects && @related_subjects.index(thing)
|
194
|
+
thing.add_related_subject(self) unless thing.related_subjects && thing.related_subjects.index(self)
|
195
|
+
end
|
196
|
+
|
197
|
+
def remove_related_subject(thing)
|
198
|
+
return unless @related_subjects
|
199
|
+
@related_subjects.delete(thing)
|
200
|
+
thing.remove_related_subject(self) if thing.related_subjects && thing.related_subjects.index(self)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
data/lib/frbr/item.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module FRBR
|
2
|
+
module Item
|
3
|
+
include FRBR::Group1
|
4
|
+
include FRBR::Group3
|
5
|
+
attr_reader :exemplar_of, :owners
|
6
|
+
alias :manifestation :exemplar_of
|
7
|
+
|
8
|
+
def equivalents
|
9
|
+
equivalents = []
|
10
|
+
if self.exemplar_of
|
11
|
+
self.exemplar_of.exemplars.each do | item |
|
12
|
+
next if item == self
|
13
|
+
equivalents << item
|
14
|
+
end
|
15
|
+
end
|
16
|
+
equivalents
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_exemplar_of(manifestation)
|
20
|
+
raise ArgumentError, "Must be the exemplar of a manifestation" unless manifestation.is_a?(FRBR::Manifestation)
|
21
|
+
@exemplar_of = manifestation
|
22
|
+
manifestation.add_exemplar(self) unless manifestation.exemplars && manifestation.exemplars.index(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :is_item_of, :is_exemplar_of
|
26
|
+
|
27
|
+
def clear_exemplar_of
|
28
|
+
if @exemplar_of && !@exemplar_of.nil?
|
29
|
+
if @exemplar_of.exemplars && @exemplar_of.exemplars.index(self)
|
30
|
+
@exemplar_of.remove_exemplar(self)
|
31
|
+
end
|
32
|
+
@exemplar_of = nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def has_owner?(agent)
|
37
|
+
return true if @owners && @owners.index(agent)
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :clear_item_of, :clear_exemplar_of
|
42
|
+
|
43
|
+
def add_owner(owner)
|
44
|
+
raise ArgumentError, "Owner must be a Group 2 entity" unless owner.is_a?(FRBR::Group2)
|
45
|
+
@owners ||= []
|
46
|
+
@owners << owner unless @owners.index(owner)
|
47
|
+
owner.add_ownership(self) unless owner.owner_of?(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove_owner(owner)
|
51
|
+
@owners.delete(owner)
|
52
|
+
owner.remove_ownership(self) if owner.owner_of?(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_related(expression)
|
56
|
+
(action, relationship) = this_method.split("_")
|
57
|
+
self.add_relationship_to_entity(expression, relationship.to_sym, FRBR::Item, true)
|
58
|
+
end
|
59
|
+
|
60
|
+
def remove_related(expression)
|
61
|
+
(action, relationship) = this_method.split("_")
|
62
|
+
self.remove_relationship_from_entity(expression, relationship.to_sym, FRBR::Item, true)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.valid_relationships
|
66
|
+
{:reconfiguration=>:reconfiguration_of, :accompanied_by=>:accompanies, :described_in=>:describes, :contains=>:contained_in, :reproduction=>:reproduction_of, :related=>:related}
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def self.included(o)
|
71
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
72
|
+
add_method_aliases
|
73
|
+
end
|
74
|
+
def self.extended(o)
|
75
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
76
|
+
add_method_aliases
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.add_method_aliases
|
80
|
+
self.valid_relationships.to_a.flatten.each do |rel|
|
81
|
+
next if rel == :related
|
82
|
+
alias_method "add_#{rel}".to_sym, :add_related
|
83
|
+
alias_method "remove_#{rel}".to_sym, :remove_related
|
84
|
+
alias_method rel, :related
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module FRBR
|
2
|
+
module Manifestation
|
3
|
+
include FRBR::Group1
|
4
|
+
include FRBR::Group3
|
5
|
+
attr_reader :producers, :embodiment_of, :exemplars
|
6
|
+
|
7
|
+
alias :expression :embodiment_of
|
8
|
+
alias :items :exemplars
|
9
|
+
|
10
|
+
def equivalents
|
11
|
+
equivalents = []
|
12
|
+
if self.embodiment_of
|
13
|
+
self.embodiment_of.embodiments.each do | manifestation |
|
14
|
+
next if manifestation == self
|
15
|
+
equivalents << manifestation
|
16
|
+
end
|
17
|
+
end
|
18
|
+
equivalents
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_embodiment_of(expression)
|
22
|
+
raise ArgumentError, "Must be the embodiment of an expression" unless expression.is_a?(FRBR::Expression)
|
23
|
+
@embodiment_of = expression
|
24
|
+
expression.add_embodiment(self) unless expression.embodiments && expression.embodiments.index(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :is_manifestation_of, :is_embodiment_of
|
28
|
+
|
29
|
+
def clear_embodiment_of
|
30
|
+
if @embodiment_of && !@embodiment_of.nil?
|
31
|
+
if @embodiment_of.embodiments && @embodiment_of.embodiments.index(self)
|
32
|
+
@embodiment_of.remove_embodiment(self)
|
33
|
+
end
|
34
|
+
@embodiment_of = nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :clear_manifestation_of, :clear_embodiment_of
|
39
|
+
|
40
|
+
def add_exemplar(item)
|
41
|
+
raise ArgumentError, "Exemplar must an item" unless item.is_a?(FRBR::Item)
|
42
|
+
@exemplars ||= []
|
43
|
+
@exemplars << item unless @exemplars.index(item)
|
44
|
+
item.is_exemplar_of(self)
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method :add_item, :add_exemplar
|
48
|
+
|
49
|
+
def remove_exemplar(item)
|
50
|
+
@exemplars.delete(item) if @exemplars
|
51
|
+
item.clear_exemplar_of
|
52
|
+
end
|
53
|
+
|
54
|
+
alias_method :remove_item, :remove_exemplar
|
55
|
+
|
56
|
+
def add_producer(producer)
|
57
|
+
raise ArgumentError, "Producer must be a Group 2 entity" unless producer.is_a?(FRBR::Group2)
|
58
|
+
@producers ||= []
|
59
|
+
@producers << producer unless @producers.index(producer)
|
60
|
+
producer.add_production(self) unless producer.producer_of?(self)
|
61
|
+
end
|
62
|
+
|
63
|
+
def remove_producer(producer)
|
64
|
+
@producers.delete(producer)
|
65
|
+
producer.remove_production(self) if producer.producer_of?(self)
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_producer?(agent)
|
69
|
+
return true if @producers && @producers.index(agent)
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_related(expression)
|
74
|
+
(action, relationship) = this_method.split("_")
|
75
|
+
self.add_relationship_to_entity(expression, relationship.to_sym, FRBR::Manifestation, true)
|
76
|
+
end
|
77
|
+
|
78
|
+
def remove_related(expression)
|
79
|
+
(action, relationship) = this_method.split("_")
|
80
|
+
self.remove_relationship_from_entity(expression, relationship.to_sym, FRBR::Manifestation, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.valid_relationships
|
84
|
+
{:accompanied_by=>:accompanies, :described_in=>:describes, :contains=>:contained_in, :reproduction=>:reproduction_of, :related=>:related}
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def self.included(o)
|
89
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
90
|
+
add_method_aliases
|
91
|
+
end
|
92
|
+
def self.extended(o)
|
93
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
94
|
+
add_method_aliases
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.add_method_aliases
|
98
|
+
self.valid_relationships.to_a.flatten.each do |rel|
|
99
|
+
next if rel == :related
|
100
|
+
alias_method "add_#{rel}".to_sym, :add_related
|
101
|
+
alias_method "remove_#{rel}".to_sym, :remove_related
|
102
|
+
alias_method rel, :related
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/frbr/object.rb
ADDED
data/lib/frbr/person.rb
ADDED
data/lib/frbr/place.rb
ADDED
data/lib/frbr/work.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module FRBR
|
2
|
+
module Work
|
3
|
+
include FRBR::Group1
|
4
|
+
include FRBR::Group3
|
5
|
+
attr_reader :creators, :subjects, :realizations, :related_works, :valid_relationships
|
6
|
+
alias :expressions :realizations
|
7
|
+
|
8
|
+
def add_creator(creator)
|
9
|
+
raise ArgumentError, "Creator must be a Group 2 entity" unless creator.is_a?(FRBR::Group2)
|
10
|
+
@creators ||= []
|
11
|
+
@creators << creator unless @creators.index(creator)
|
12
|
+
creator.add_creation(self) unless creator.creator_of?(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_creator(creator)
|
16
|
+
@creators.delete(creator)
|
17
|
+
creator.remove_creation(self) if creator.creator_of?(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_creator?(agent)
|
21
|
+
return true if @creators && @creators.index(agent)
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_realization(expression)
|
26
|
+
raise ArgumentError, "Only Expressions can be realizations" unless expression.is_a?(FRBR::Expression)
|
27
|
+
@realizations ||= []
|
28
|
+
@realizations << expression unless @realizations.index(expression)
|
29
|
+
expression.is_realization_of(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :add_expression, :add_realization
|
33
|
+
|
34
|
+
def remove_realization(expression)
|
35
|
+
@realizations.delete(expression) if realizations
|
36
|
+
expression.clear_realization_of
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :remove_expression, :remove_realization
|
40
|
+
|
41
|
+
def add_subject(subject)
|
42
|
+
raise ArgumentError, "Subject must be a Group 3 entity" unless subject.is_a?(FRBR::Group3)
|
43
|
+
@subjects ||= []
|
44
|
+
@subjects << subject
|
45
|
+
subject.add_subject_of(self) unless subject.subject_of && subject.subject_of.index(self)
|
46
|
+
end
|
47
|
+
|
48
|
+
def remove_subject(subject)
|
49
|
+
@subjects.delete(subject) if @subjects
|
50
|
+
subject.remove_subject_of(self) if subject.subject_of && subject.subject_of.index(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_related(work)
|
54
|
+
(action, relationship) = this_method.split("_")
|
55
|
+
self.add_relationship_to_entity(work, relationship.to_sym, FRBR::Work, true)
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_related(work)
|
59
|
+
(action, relationship) = this_method.split("_")
|
60
|
+
self.remove_relationship_from_entity(work, relationship.to_sym, FRBR::Work, true)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.valid_relationships
|
64
|
+
{:derivative=>:based_on, :described_in=>:describes, :complemented_by=>:complements, :augmented_by=>:augments, :contains=>:contained_in, :preceded_by=>:succeeded_by, :adaptation_of=>:adaptation, :related=>:related}
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def self.included(o)
|
69
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
70
|
+
add_method_aliases
|
71
|
+
end
|
72
|
+
def self.extended(o)
|
73
|
+
FRBR::Group1.check_frbr_validity(o, self.name)
|
74
|
+
add_method_aliases
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.add_method_aliases
|
78
|
+
self.valid_relationships.to_a.flatten.each do |rel|
|
79
|
+
next if rel == :related
|
80
|
+
alias_method "add_#{rel}".to_sym, :add_related
|
81
|
+
alias_method "remove_#{rel}".to_sym, :remove_related
|
82
|
+
alias_method rel, :related
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/frbr.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/frbr/groups'
|
2
|
+
require File.dirname(__FILE__) + '/frbr/concept'
|
3
|
+
require File.dirname(__FILE__) + '/frbr/corporate_body'
|
4
|
+
require File.dirname(__FILE__) + '/frbr/event'
|
5
|
+
require File.dirname(__FILE__) + '/frbr/family'
|
6
|
+
require File.dirname(__FILE__) + '/frbr/object'
|
7
|
+
require File.dirname(__FILE__) + '/frbr/person'
|
8
|
+
require File.dirname(__FILE__) + '/frbr/place'
|
9
|
+
require File.dirname(__FILE__) + '/frbr/work'
|
10
|
+
require File.dirname(__FILE__) + '/frbr/expression'
|
11
|
+
require File.dirname(__FILE__) + '/frbr/manifestation'
|
12
|
+
require File.dirname(__FILE__) + '/frbr/item'
|
13
|
+
|
14
|
+
|
15
|
+
module Kernel
|
16
|
+
def self.constant(const)
|
17
|
+
const = const.to_s.dup
|
18
|
+
base = const.sub!(/^::/, '') ? Object : ( self.kind_of?(Module) ? self : self.class )
|
19
|
+
const.split(/::/).inject(base){ |mod, name| mod.const_get(name) }
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: frbr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ross Singer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-20 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A set of modules for creating simple FRBR (Functional Requirements for Bibliographic Resources) relationships between objects. Includes Group 1, 2 and 3 entities.
|
23
|
+
email: rossfsinger@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README
|
31
|
+
files:
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- lib/frbr.rb
|
35
|
+
- lib/frbr/concept.rb
|
36
|
+
- lib/frbr/corporate_body.rb
|
37
|
+
- lib/frbr/event.rb
|
38
|
+
- lib/frbr/expression.rb
|
39
|
+
- lib/frbr/family.rb
|
40
|
+
- lib/frbr/groups.rb
|
41
|
+
- lib/frbr/item.rb
|
42
|
+
- lib/frbr/manifestation.rb
|
43
|
+
- lib/frbr/object.rb
|
44
|
+
- lib/frbr/person.rb
|
45
|
+
- lib/frbr/place.rb
|
46
|
+
- lib/frbr/work.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/rsinger/ruby-frbr
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: A set of modules for creating simple FRBR relationships between objects.
|
81
|
+
test_files: []
|
82
|
+
|