Class: Marcxella::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/marcxella/record.rb

Overview

Wrapper for a record element

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Record

Returns a new instance of Record.

Since:

  • 0.1.0



9
10
11
12
13
# File 'lib/marcxella/record.rb', line 9

def initialize(node)
  @node = node
  @leader = node.css('leader').text
  @fields = node.css('controlfield, datafield').map{|f| objectify f}
end

Instance Attribute Details

#fieldsArray<ControlField, DataField> (readonly)

The control and data fields of the record

Returns:

Since:

  • 0.1.0



25
26
27
# File 'lib/marcxella/record.rb', line 25

def fields
  @fields
end

#leaderString (readonly)

the record leader

Returns:

  • (String)

    the current value of leader

Since:

  • 0.1.0



7
8
9
# File 'lib/marcxella/record.rb', line 7

def leader
  @leader
end

#nodeNokogiri::XML::Document (readonly)

the wrapped record element node

Returns:

  • (Nokogiri::XML::Document)

    the current value of node

Since:

  • 0.1.0



7
8
9
# File 'lib/marcxella/record.rb', line 7

def node
  @node
end

Instance Method Details

#addedEntriesArray<DataField>

The added entry fields (70X-75X)

Returns:

See Also:

Since:

  • 0.1.0



135
136
137
# File 'lib/marcxella/record.rb', line 135

def addedEntries
  tag_range("700", "75X")
end

#codesArray<DataField>

The numbers and code fields (01X-09X)

Returns:

See Also:

Since:

  • 0.1.0



72
73
74
# File 'lib/marcxella/record.rb', line 72

def codes
  tag_range("010", "09X")
end

#controlFieldsArray<ControlField>

The control fields (00X)

Returns:

See Also:

Since:

  • 0.1.0



63
64
65
# File 'lib/marcxella/record.rb', line 63

def controlFields
  tag_range("001", "009")
end

#descriptionArray<DataField>

The physical description fields (3XX)



99
100
101
# File 'lib/marcxella/record.rb', line 99

def description
  tag_range("300", "399")
end

#editionArray<DataField>

The edition- and imprint-related fields (25X-28X)



90
91
92
# File 'lib/marcxella/record.rb', line 90

def edition
  tag_range("250", "28X")
end

#field(tag) ⇒ Array<DataField>, Array<ControlField>

Get fields by a tag

Parameters:

  • tag (String)

    Tag of the field to get.

Returns:

Since:

  • 0.1.0



19
20
21
# File 'lib/marcxella/record.rb', line 19

def field(tag)
  return @fields.select{|f| f.tag == tag}
end

#holdingsArray<DataField>

The holdings, alternate graphics, etc fields (841-88X)



162
163
164
# File 'lib/marcxella/record.rb', line 162

def holdings
  tag_range("841", "88X")
end

#include?(tag, code = nil) ⇒ boolean

Does the record include a field with a specific tag?

Returns:

  • (boolean)

    true if there is at least one control or data field with the specified tag.

Since:

  • 0.1.0



33
34
35
# File 'lib/marcxella/record.rb', line 33

def include?(tag, code = nil)
  not field(tag, code).empty?
end

#isbnsArray<String>

The International Standard Book Number (020$a)

Returns:

  • (Array<String>)

    An array of ISBNs

Since:

  • 0.1.0



179
180
181
# File 'lib/marcxella/record.rb', line 179

def isbns
  subfield("020", "a").map{|s| s.value}
end

#issnsArray<String>

The International Standard Serial Number (022$a)

Returns:

  • (Array<String>)

    An array of ISSNs

Since:

  • 0.1.0



186
187
188
# File 'lib/marcxella/record.rb', line 186

def issns
  subfield("022", "a").map{|s| s.value}
end

#lccnString

The Library of Congress Control Number (010$a). Only returns the $a

subfields, nothing from the $b or $z

Returns:

  • (String)

    the LCCN, nil if there is none.

Since:

  • 0.1.0



170
171
172
173
174
# File 'lib/marcxella/record.rb', line 170

def lccn
  s = subfield("010", "a")
  return nil if s.empty?
  s.first.value
end

#linkingArray<DataField>

The linking entry fields (76X-78X)

Returns:

See Also:

Since:

  • 0.1.0



144
145
146
# File 'lib/marcxella/record.rb', line 144

def linking
  tag_range("760", "78X")
end

#mainEntryDataField

The record’s main entry field. Every record should have one (and only one) of the 1XX fields (100, 110, 111, 130).

Returns:

See Also:

Since:

  • 0.1.0



44
45
46
# File 'lib/marcxella/record.rb', line 44

def mainEntry
  tag_range("100", "1XX").first
end

#notesArray<DataField>

The note statement fields (5XX)

Returns:

See Also:

Since:

  • 0.1.0



117
118
119
# File 'lib/marcxella/record.rb', line 117

def notes
  tag_range("500", "59X")
end

#seriesArray<DataField>

The series statement fields (4XX)

Returns:

See Also:

Since:

  • 0.1.0



108
109
110
# File 'lib/marcxella/record.rb', line 108

def series
  tag_range("400", "499")
end

#seriesAddedArray<DataField>

The series added entry fields (80X-83X)

Returns:

See Also:

Since:

  • 0.1.0



153
154
155
# File 'lib/marcxella/record.rb', line 153

def seriesAdded
  tag_range("800", "83X")
end

#subfield(tag, code) ⇒ Array<SubField>

get a subfield from matching fields, for instance all 651$a subfields

Parameters:

  • tag (String)

    tag to match

  • code (String)

    code to match

Returns:

  • (Array<SubField>)

    an array of matching subfields

Since:

  • 0.1.0



209
210
211
# File 'lib/marcxella/record.rb', line 209

def subfield(tag, code)
  field(tag).map{|f| f.subfields.select{|s| s.code == code } }.flatten
end

#subjectsArray<DataField>

The subject access fields (6XX)

Returns:

See Also:

Since:

  • 0.1.0



126
127
128
# File 'lib/marcxella/record.rb', line 126

def subjects
  tag_range("600", "69X")
end

#titlesArray<DataField>

The title- and title-related fields (20X-24X)



81
82
83
# File 'lib/marcxella/record.rb', line 81

def titles
  tag_range("200", "24X2")
end

#titleStatementDataField

The record’s title statement. That is, its 245 field

Returns:

See Also:

Since:

  • 0.1.0



54
55
56
# File 'lib/marcxella/record.rb', line 54

def titleStatement
  field("245").first
end