-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpremis_agent.rb
More file actions
44 lines (36 loc) · 1.35 KB
/
premis_agent.rb
File metadata and controls
44 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Agent_Types = ["software", "person", "organization"]
Agent_Map = {
"web service" => "software",
"software" => "software",
"affiliate" => "organization"
}
unless DB.table_exists? (:premis_agents)
DB.create_table :premis_agents do
String :id, :primary_key=>true, :type=>'varchar(255)'
String :name, :size=>255
String :type, :size=>20, :null=>false
Text :note # additional agent note which may include external tool information
end
end
class PremisAgent < Sequel::Model(:premis_agents)
one_to_many :premis_events # :constraint => :destroy # an agent can create 0-n events.
# validate the agent type value which is a daitss defined controlled vocabulary
def validateType
unless Agent_Types.include?(@type)
raise "value #{@type} is not a valid agent type value"
end
end
def fromPremis premis
self.id = premis.find_first("premis:agentIdentifier/premis:agentIdentifierValue", NAMESPACES).content
self.name = premis.find_first("premis:agentName", NAMESPACES).content
type = premis.find_first("premis:agentType", NAMESPACES).content
self.type = Agent_Map[type.downcase]
validateType
note = premis.find_first("*[local-name()='agentNote']", NAMESPACES)
self.note = note.content if note
end
def to_premis_xml
# TODO agent note?
agent :id => self.id, :name => self.name, :type => self.type
end
end