Class: EventsDS
- Inherits:
-
ActiveFedora::NokogiriDatastream
- Object
- ActiveFedora::NokogiriDatastream
- EventsDS
- Defined in:
- lib/datastreams/events_ds.rb
Class Method Summary collapse
-
.xml_template ⇒ Object
Default EventsDS xml.
Instance Method Summary collapse
-
#add_event(type, who, message) ⇒ Object
Adds an event to the datastream.
-
#each_event {|type, who, timestamp, message| ... } ⇒ Object
Returns all the events in the datastream.
-
#find_events_by_type(tag) {|who, timestamp, message| ... } ⇒ Object
Finds events with the desired type attribute.
-
#initialize(attrs = nil) ⇒ EventsDS
constructor
A new instance of EventsDS.
Constructor Details
#initialize(attrs = nil) ⇒ EventsDS
Returns a new instance of EventsDS.
18 19 20 21 |
# File 'lib/datastreams/events_ds.rb', line 18 def initialize(attrs=nil) super @attributes[:versionable] = false end |
Class Method Details
.xml_template ⇒ Object
Default EventsDS xml
11 12 13 14 15 16 |
# File 'lib/datastreams/events_ds.rb', line 11 def self.xml_template builder = Nokogiri::XML::Builder.new do |xml| xml.events end return builder.doc end |
Instance Method Details
#add_event(type, who, message) ⇒ Object
Adds an event to the datastream
27 28 29 30 31 32 |
# File 'lib/datastreams/events_ds.rb', line 27 def add_event(type, who, ) ev = ng_xml.create_element "event", , :type => type, :who => who, :when => Time.now.xmlschema ng_xml.root.add_child(ev) self.dirty = true end |
#each_event {|type, who, timestamp, message| ... } ⇒ Object
Returns all the events in the datastream
52 53 54 55 56 |
# File 'lib/datastreams/events_ds.rb', line 52 def each_event(&block) find_by_terms(:event).each do |node| block.call(node['type'], node['who'], Time.parse(node['when']), node.content) end end |
#find_events_by_type(tag) {|who, timestamp, message| ... } ⇒ Object
Finds events with the desired type attribute
40 41 42 43 44 |
# File 'lib/datastreams/events_ds.rb', line 40 def find_events_by_type(tag, &block) find_by_terms(:event).xpath("//event[@type='#{tag}']").each do |node| block.call(node['who'], Time.parse(node['when']), node.content) end end |