Class: Merritt::TIND::Record
- Inherits:
-
Object
- Object
- Merritt::TIND::Record
- Defined in:
- lib/merritt/tind/record.rb
Constant Summary collapse
- IDENTIFIER =
'identifier'.freeze
- DATESTAMP =
'datestamp'.freeze
Instance Attribute Summary collapse
-
#datestamp ⇒ Object
readonly
Returns the value of attribute datestamp.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
- .earlier(r1, r2) ⇒ Object
- .from_hash(h) ⇒ Object
-
.from_oai(oai_record) ⇒ Object
Constructs a new Record wrapping the specified record.
- .later(r1, r2) ⇒ Object
Instance Method Summary collapse
- #content_uri ⇒ Object
- #dc_creators ⇒ Object
- #dc_dates ⇒ Object
- #dc_identifiers ⇒ Object
- #dc_titles ⇒ Object
- #erc ⇒ Object
-
#initialize(identifier:, datestamp:, oai_metadata: nil) ⇒ Record
constructor
A new instance of Record.
- #local_id ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(identifier:, datestamp:, oai_metadata: nil) ⇒ Record
Returns a new instance of Record.
14 15 16 17 18 |
# File 'lib/merritt/tind/record.rb', line 14 def initialize(identifier:, datestamp:, oai_metadata: nil) @identifier = identifier @datestamp = datestamp @metadata = end |
Instance Attribute Details
#datestamp ⇒ Object (readonly)
Returns the value of attribute datestamp.
11 12 13 |
# File 'lib/merritt/tind/record.rb', line 11 def datestamp @datestamp end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
10 11 12 |
# File 'lib/merritt/tind/record.rb', line 10 def identifier @identifier end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/merritt/tind/record.rb', line 12 def @metadata end |
Class Method Details
.earlier(r1, r2) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/merritt/tind/record.rb', line 80 def earlier(r1, r2) return r1 if r2.nil? return r2 if r1.nil? return r1 if (r1.datestamp <=> r2.datestamp) < 0 r2 end |
.from_hash(h) ⇒ Object
88 89 90 91 92 |
# File 'lib/merritt/tind/record.rb', line 88 def from_hash(h) return unless h Record.new(identifier: h[IDENTIFIER], datestamp: h[DATESTAMP]) end |
.from_oai(oai_record) ⇒ Object
Constructs a new Merritt::TIND::Record wrapping the specified record.
97 98 99 100 101 102 103 104 |
# File 'lib/merritt/tind/record.rb', line 97 def from_oai(oai_record) raise ArgumentError, "can't parse nil record" unless oai_record header = oai_record.header identifier = header.identifier datestamp = header.datestamp && Time.parse(header.datestamp) Record.new(identifier: identifier, datestamp: datestamp, oai_metadata: oai_record.) end |
.later(r1, r2) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/merritt/tind/record.rb', line 72 def later(r1, r2) return r1 if r2.nil? return r2 if r1.nil? return r1 if (r1.datestamp <=> r2.datestamp) > 0 r2 end |
Instance Method Details
#content_uri ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/merritt/tind/record.rb', line 51 def content_uri @content_uri ||= begin # TODO: something smarter when we know the real requirements content_url = dc_identifiers.find do |dc_id| dc_id.start_with?('http') && dc_id.end_with?('jpg') end content_url && URI.parse(content_url) end end |
#dc_creators ⇒ Object
47 48 49 |
# File 'lib/merritt/tind/record.rb', line 47 def dc_creators @dc_creators ||= REXML::XPath.match(, './/dc:creator').map(&:text) end |
#dc_dates ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/merritt/tind/record.rb', line 35 def dc_dates @dc_dates ||= begin REXML::XPath.match(, './/dc:date') .map(&:text) .map { |t| Time.parse(t) } end end |
#dc_identifiers ⇒ Object
31 32 33 |
# File 'lib/merritt/tind/record.rb', line 31 def dc_identifiers @dc_identifiers ||= REXML::XPath.match(, './/dc:identifier').map(&:text) end |
#dc_titles ⇒ Object
43 44 45 |
# File 'lib/merritt/tind/record.rb', line 43 def dc_titles @dc_titles ||= REXML::XPath.match(, './/dc:title').map(&:text) end |
#erc ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/merritt/tind/record.rb', line 20 def erc # TODO: something smarter when we know the real requirements { 'what' => identifier, 'where' => local_id, 'when' => dc_dates.first || datestamp, 'when/created' => dc_dates.first || datestamp, 'when/modified' => datestamp } end |
#local_id ⇒ Object
61 62 63 64 |
# File 'lib/merritt/tind/record.rb', line 61 def local_id # TODO: something smarter when we know the real requirements dc_identifiers.first || identifier end |
#to_h ⇒ Object
66 67 68 |
# File 'lib/merritt/tind/record.rb', line 66 def to_h { IDENTIFIER => identifier, DATESTAMP => datestamp } end |