Class: Hip3::SerialCopy

Inherits:
Holding show all
Defined in:
app/models/hip3/serial_copy.rb

Overview

data, and the bib loads it at once for all copies, in one fetch.

Constant Summary collapse

@@Field_labels =
{:location => 'Location', :collection => 'Collection', :call_no => 'Call No.', :copy_str => 'Copy No.', :status => 'Status', :notes => 'Notes'}

Instance Attribute Summary collapse

Attributes inherited from Holding

#bib, #call_no, #collection_str, #copy_str, #id, #location_str, #notes, #status_str

Instance Method Summary collapse

Methods inherited from Holding

#dummy?, #textValue

Constructor Details

#initialize(argBibObj, serialXmlElement = nil) ⇒ SerialCopy

Returns a new instance of SerialCopy.



11
12
13
14
15
16
17
# File 'app/models/hip3/serial_copy.rb', line 11

def initialize(argBibObj, serialXmlElement=nil)
	self.bib = argBibObj
	self.items_loaded = false
	if ( serialXmlElement ) 
		loadFromSerialElement( serialXmlElement )
	end
end

Instance Attribute Details

#itemsObject

array of items



7
8
9
# File 'app/models/hip3/serial_copy.rb', line 7

def items
  @items
end

#items_loadedObject

Returns the value of attribute items_loaded.



8
9
10
# File 'app/models/hip3/serial_copy.rb', line 8

def items_loaded
  @items_loaded
end

#runsObject

array of run types/statements



9
10
11
# File 'app/models/hip3/serial_copy.rb', line 9

def runs
  @runs
end

Instance Method Details

#coverage_strObject

Not too useful, use coverage_str_to_a instead usually



59
60
61
# File 'app/models/hip3/serial_copy.rb', line 59

def coverage_str
	return runs.to_s
end

#coverage_str_to_aObject

Over-riding



64
65
66
67
68
69
70
71
72
# File 'app/models/hip3/serial_copy.rb', line 64

def coverage_str_to_a
	runs.collect do |r|
      s = ''
      (s << r[:label] << ": ") if (! r[:label].blank?) && r[:label] != "Main run"
      s << r[:statement]
      s << '-- ' << r[:note] if r[:note]
      s
    end
end

#items_loaded?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/hip3/serial_copy.rb', line 25

def items_loaded?
	return (items_loaded == true)
end

#loadFromSerialElement(serialElement) ⇒ Object



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
# File 'app/models/hip3/serial_copy.rb', line 29

def loadFromSerialElement( serialElement )
	self.location_str = serialElement.at('/location').inner_text
	self.id = serialElement.at('/copykey').inner_text
	
	# Okay, this part is potentially fragile, we have to pull out based on
	# order in the XML, not sure if that can change. Sorry, that's HIP for you.
	copyElements = serialElement.search('/copy/cell/data/text').collect {|e| e.inner_text}
	# Fix this to use field lookup
	self.location_str = bib.copy_field_lookup.text_value_for(copyElements, @@Field_labels[:location])
	self.collection_str =  bib.copy_field_lookup.text_value_for(copyElements, @@Field_labels[:collection])
	self.call_no = bib.copy_field_lookup.text_value_for(copyElements, @@Field_labels[:call_no])
	self.copy_str = bib.copy_field_lookup.text_value_for(copyElements, @@Field_labels[:copy_str])
	self.status_str = bib.copy_field_lookup.text_value_for(copyElements, @@Field_labels[:status])
	self.notes = bib.copy_field_lookup.text_value_for(copyElements, @@Field_labels[:notes])
	
	
	#Okay, got to get the 'runs' for summary holdings info.
	self.runs ||= []
	serialElement.search('/runlist/run').each do |run|
		label = run.at('/runlabel').inner_text
		run.search('/data/rundata').each do |rundata|
        run = {:label => label, :statement => textValue(rundata.at('/text'))}
        run[:note] = textValue(rundata.at('/note'))
		  
        self.runs.push( run )
		end
	end
end

#register_item(item) ⇒ Object



74
75
76
77
78
79
80
# File 'app/models/hip3/serial_copy.rb', line 74

def register_item(item)
	items ||= []
	
	unless items.include?(item)
		items.push(item)
	end
end