Class: PBCore::V2::Base
- Inherits:
-
Object
show all
- Includes:
- SAXMachine
- Defined in:
- lib/pb_core/v2/base.rb
Direct Known Subclasses
Affiliate, Annotated, Annotation, Collection, Contributor, ContributorType, Coverage, CoverageInfo, Creator, DateType, Description, DocumentType, EssenceTrack, Extension, ExtensionWrap, Genre, Identifier, InstantiationRelation, InstantiationType, Measurement, Publisher, Relation, Rights, Standard, Subject, Title, Type
Class Method Summary
collapse
Instance Method Summary
collapse
-
#detect_element(element_name, options = {}) ⇒ Object
this is a handy method for getting info out of the doc since so many of the elements can be multiple, and you may need to pick just one, this method lets you do that by specifying the element, then how to select it by matching values to an attr.
Class Method Details
.collection_group ⇒ Object
.instantiation_group ⇒ Object
42
|
# File 'lib/pb_core/v2/base.rb', line 42
def self.instantiation_group; include PBCore::V2::InstantiationGroup; end
|
.source_version_group ⇒ Object
.start_end_time_group ⇒ Object
Instance Method Details
#detect_element(element_name, options = {}) ⇒ Object
this is a handy method for getting info out of the doc since so many of the elements can be multiple, and you may need to pick just one, this method lets you do that by specifying the element, then how to select it by matching values to an attr. It can return just the first one of the element by default. It also can get the value from the element rather than return the element
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/pb_core/v2/base.rb', line 51
def detect_element(element_name, options={})
atr = options[:match_attr] || :type
values = Array(options[:match_value] || nil)
default_first = options.key?(:default_first) ? options[:default_first] : true
method = options.key?(:value) ? options[:value] : :value
l = Array(self.send(element_name))
return nil if l.size <= 0
e = nil
values.each{|v|
e = l.detect do |i|
case v.class.name
when 'Regexp'
v =~ element_value(i, atr)
else
element_value(i, atr) == standardize(v)
end
end
break if e
}
e = l.first if default_first && e.nil?
e = (e && method && e.respond_to?(method)) ? e.send(method) : nil
return e
end
|