Sha256: e18bc73b4990be6b2f7d1fbe7910a9c5efadb7353ee41b235b405a717e050e54

Contents?: true

Size: 1.33 KB

Versions: 17

Compression:

Stored size: 1.33 KB

Contents

require  "nom"

module ActiveFedora
  class NomDatastream < File

    include Datastreams::NokogiriDatastreams

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

    def self.terminology_options
      @terminology_options
    end

    def self.terminology
      @terminology
    end

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

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

    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

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

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

    protected

    def default_mime_type
      'text/xml'
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active-fedora-9.0.8 lib/active_fedora/nom_datastream.rb
active-fedora-9.5.0 lib/active_fedora/nom_datastream.rb
active-fedora-9.4.3 lib/active_fedora/nom_datastream.rb
active-fedora-9.4.2 lib/active_fedora/nom_datastream.rb
active-fedora-9.4.1 lib/active_fedora/nom_datastream.rb
active-fedora-9.4.0 lib/active_fedora/nom_datastream.rb
active-fedora-9.3.0 lib/active_fedora/nom_datastream.rb
active-fedora-9.2.1 lib/active_fedora/nom_datastream.rb
active-fedora-9.2.0 lib/active_fedora/nom_datastream.rb
active-fedora-9.2.0.rc2 lib/active_fedora/nom_datastream.rb
active-fedora-9.2.0.rc1 lib/active_fedora/nom_datastream.rb
active-fedora-9.1.2 lib/active_fedora/nom_datastream.rb
active-fedora-9.1.1 lib/active_fedora/nom_datastream.rb
active-fedora-9.1.0 lib/active_fedora/nom_datastream.rb
active-fedora-9.1.0.rc1 lib/active_fedora/nom_datastream.rb
active-fedora-9.0.6 lib/active_fedora/nom_datastream.rb
active-fedora-9.0.5 lib/active_fedora/nom_datastream.rb