Class: ActiveFedora::NomDatastream

Inherits:
File
  • Object
show all
Includes:
Datastreams::NokogiriDatastreams
Defined in:
lib/active_fedora/nom_datastream.rb

Constant Summary

Constants included from AttributeMethods

AttributeMethods::AttrNames

Instance Attribute Summary

Attributes included from File::Attributes

#mime_type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Datastreams::NokogiriDatastreams

#autocreate?, #content, #content=, #content_changed?, #ng_xml, #ng_xml=, #ng_xml_changed?, #ng_xml_doesnt_change!, #ng_xml_will_change!, #refresh_attributes, #remote_content, #to_xml, #xml_loaded

Methods inherited from File

#==, #attribute_will_change!, #changed?, #check_fixity, #content, #content=, #content_changed?, #datastream_will_change!, #described_by, #exists!, #freeze, #frozen?, #initialize, #inspect, #ldp_connection, #ldp_source, #metadata, #metadata?, #new_record?, #readonly?, #refresh, #reload, #remote_content, #uri=

Methods included from Querying

#default_sort_params, extended

Methods included from Identifiable

#id, #id=, #pid, #uri

Methods included from AttributeMethods

#[], #[]=, #attribute_names, #attributes

Methods included from Versionable

#create_version, #has_versions?, #model_type, #restore_version, #versions

Methods included from Persistence

#delete, #destroy, #destroyed?, #eradicate, #new_record?, #persisted?, #save, #save!, #update

Methods included from File::Streaming

#headers, #stream

Methods included from File::Attributes

#digest, #dirty_size, #empty?, #has_content?, #original_name, #original_name=, #persisted_size, #size

Constructor Details

This class inherits a constructor from ActiveFedora::File

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/active_fedora/nom_datastream.rb', line 50

def method_missing method, *args, &block
  if ng_xml.respond_to? method
    ng_xml.send(method, *args, &block)
  else
    super
  end
end

Class Method Details

.decorate_ng_xml(xml) ⇒ Object



21
22
23
24
25
# File 'lib/active_fedora/nom_datastream.rb', line 21

def self.decorate_ng_xml(xml)
  xml.set_terminology terminology_options, &terminology
  xml.nom!
  xml
end

.set_terminology(options = {}, &block) ⇒ Object



8
9
10
11
# File 'lib/active_fedora/nom_datastream.rb', line 8

def self.set_terminology(options = {}, &block)
  @terminology_options = options || {}
  @terminology = block
end

.terminologyObject



17
18
19
# File 'lib/active_fedora/nom_datastream.rb', line 17

def self.terminology
  @terminology
end

.terminology_optionsObject



13
14
15
# File 'lib/active_fedora/nom_datastream.rb', line 13

def self.terminology_options
  @terminology_options
end

Instance Method Details

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/active_fedora/nom_datastream.rb', line 58

def respond_to? *args
  super || self.class.terminology.respond_to?(*args)
end

#serialize!Object



27
28
29
# File 'lib/active_fedora/nom_datastream.rb', line 27

def serialize!
   self.content = @ng_xml.to_s if @ng_xml
end

#to_solrObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_fedora/nom_datastream.rb', line 31

def to_solr
  solr_doc = {}

  ng_xml.terminology.flatten.select { |x| x.options[:index] }.each do |term|
    term.values.each do |v|
      Array(term.options[:index]).each do |index_as|
        solr_doc[index_as] ||= []
        if v.is_a? Nokogiri::XML::Node
          solr_doc[index_as] << v.text
        else
          solr_doc[index_as] << v
        end
      end
    end
  end

  solr_doc
end