Class: Stash::Harvester::OAIPMH::OAIRecord

Inherits:
HarvestedRecord show all
Defined in:
lib/stash/harvester/oaipmh/oai_record.rb

Overview

A utility wrapper around OAI::Record that flattens the OAI XML structure and converts types (e.g., string datestamps to Time objects)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ OAIRecord

Constructs a new Stash::Harvester::OAIPMH::OAIRecord wrapping the specified record.

Parameters:

  • record (OAI::Record)

    An OAI record as returned by OAI::Client


27
28
29
30
31
32
33
34
# File 'lib/stash/harvester/oaipmh/oai_record.rb', line 27

def initialize(record)
  super(
    identifier: record.header.identifier,
    timestamp: Time.parse(record.header.datestamp),
    deleted: record.deleted?
  )
  @metadata_root = record.deleted? ? nil : record..elements[1]
end

Instance Attribute Details

#deletedBoolean (readonly)

Returns True if the record is deleted, false otherwise.

Returns:

  • (Boolean)

    True if the record is deleted, false otherwise.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/stash/harvester/oaipmh/oai_record.rb', line 20

class OAIRecord < Stash::Harvester::HarvestedRecord

  attr_reader :metadata_root

  # Constructs a new {OAIRecord} wrapping the specified record.
  #
  # @param record [OAI::Record] An OAI record as returned by +OAI::Client+
  def initialize(record)
    super(
      identifier: record.header.identifier,
      timestamp: Time.parse(record.header.datestamp),
      deleted: record.deleted?
    )
    @metadata_root = record.deleted? ? nil : record..elements[1]
  end

  # The root (inner) XML element of the record metadata, as a string.
  # @return [String] the inner element of the record metadata.
  def content
    @content ||= begin
      formatter = REXML::Formatters::Pretty.new
      formatter.compact = true
      out = StringIO.new
      formatter.write(, out)
      out.string
    end
  end

  # Compares this record with another for structural equality.
  #
  # @return [Boolean] True if this record is equivalent to the specified record;
  #   false otherwise
  def ==(other) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
    return true if self.equal?(other)
    return false unless other.instance_of?(self.class)
    return false unless other.timestamp == timestamp
    return false unless other.deleted? == deleted?
    return false unless other.identifier == identifier
    return false unless other..to_s == .to_s
    true
  end
end

#identifierString (readonly)

Returns The OAI identifier of the record.

Returns:

  • (String)

    The OAI identifier of the record.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/stash/harvester/oaipmh/oai_record.rb', line 20

class OAIRecord < Stash::Harvester::HarvestedRecord

  attr_reader :metadata_root

  # Constructs a new {OAIRecord} wrapping the specified record.
  #
  # @param record [OAI::Record] An OAI record as returned by +OAI::Client+
  def initialize(record)
    super(
      identifier: record.header.identifier,
      timestamp: Time.parse(record.header.datestamp),
      deleted: record.deleted?
    )
    @metadata_root = record.deleted? ? nil : record..elements[1]
  end

  # The root (inner) XML element of the record metadata, as a string.
  # @return [String] the inner element of the record metadata.
  def content
    @content ||= begin
      formatter = REXML::Formatters::Pretty.new
      formatter.compact = true
      out = StringIO.new
      formatter.write(, out)
      out.string
    end
  end

  # Compares this record with another for structural equality.
  #
  # @return [Boolean] True if this record is equivalent to the specified record;
  #   false otherwise
  def ==(other) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
    return true if self.equal?(other)
    return false unless other.instance_of?(self.class)
    return false unless other.timestamp == timestamp
    return false unless other.deleted? == deleted?
    return false unless other.identifier == identifier
    return false unless other..to_s == .to_s
    true
  end
end

#metadata_rootREXML::Element (readonly)

Returns The root (inner) element of the record metadata.

Returns:

  • (REXML::Element)

    The root (inner) element of the record metadata.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/stash/harvester/oaipmh/oai_record.rb', line 20

class OAIRecord < Stash::Harvester::HarvestedRecord

  attr_reader :metadata_root

  # Constructs a new {OAIRecord} wrapping the specified record.
  #
  # @param record [OAI::Record] An OAI record as returned by +OAI::Client+
  def initialize(record)
    super(
      identifier: record.header.identifier,
      timestamp: Time.parse(record.header.datestamp),
      deleted: record.deleted?
    )
    @metadata_root = record.deleted? ? nil : record..elements[1]
  end

  # The root (inner) XML element of the record metadata, as a string.
  # @return [String] the inner element of the record metadata.
  def content
    @content ||= begin
      formatter = REXML::Formatters::Pretty.new
      formatter.compact = true
      out = StringIO.new
      formatter.write(, out)
      out.string
    end
  end

  # Compares this record with another for structural equality.
  #
  # @return [Boolean] True if this record is equivalent to the specified record;
  #   false otherwise
  def ==(other) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
    return true if self.equal?(other)
    return false unless other.instance_of?(self.class)
    return false unless other.timestamp == timestamp
    return false unless other.deleted? == deleted?
    return false unless other.identifier == identifier
    return false unless other..to_s == .to_s
    true
  end
end

#timestampTime (readonly)

Returns The datestamp of the record.

Returns:

  • (Time)

    The datestamp of the record.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/stash/harvester/oaipmh/oai_record.rb', line 20

class OAIRecord < Stash::Harvester::HarvestedRecord

  attr_reader :metadata_root

  # Constructs a new {OAIRecord} wrapping the specified record.
  #
  # @param record [OAI::Record] An OAI record as returned by +OAI::Client+
  def initialize(record)
    super(
      identifier: record.header.identifier,
      timestamp: Time.parse(record.header.datestamp),
      deleted: record.deleted?
    )
    @metadata_root = record.deleted? ? nil : record..elements[1]
  end

  # The root (inner) XML element of the record metadata, as a string.
  # @return [String] the inner element of the record metadata.
  def content
    @content ||= begin
      formatter = REXML::Formatters::Pretty.new
      formatter.compact = true
      out = StringIO.new
      formatter.write(, out)
      out.string
    end
  end

  # Compares this record with another for structural equality.
  #
  # @return [Boolean] True if this record is equivalent to the specified record;
  #   false otherwise
  def ==(other) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
    return true if self.equal?(other)
    return false unless other.instance_of?(self.class)
    return false unless other.timestamp == timestamp
    return false unless other.deleted? == deleted?
    return false unless other.identifier == identifier
    return false unless other..to_s == .to_s
    true
  end
end

Instance Method Details

#==(other) ⇒ Boolean

Compares this record with another for structural equality.

Returns:

  • (Boolean)

    True if this record is equivalent to the specified record; false otherwise


52
53
54
55
56
57
58
59
60
# File 'lib/stash/harvester/oaipmh/oai_record.rb', line 52

def ==(other) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
  return true if self.equal?(other)
  return false unless other.instance_of?(self.class)
  return false unless other.timestamp == timestamp
  return false unless other.deleted? == deleted?
  return false unless other.identifier == identifier
  return false unless other..to_s == .to_s
  true
end

#contentString

The root (inner) XML element of the record metadata, as a string.

Returns:

  • (String)

    the inner element of the record metadata.


38
39
40
41
42
43
44
45
46
# File 'lib/stash/harvester/oaipmh/oai_record.rb', line 38

def content
  @content ||= begin
    formatter = REXML::Formatters::Pretty.new
    formatter.compact = true
    out = StringIO.new
    formatter.write(, out)
    out.string
  end
end