Class: TestClass

Inherits:
Object
  • Object
show all
Includes:
FedoraLens, FedoraLens::Lenses
Defined in:
lib/test_class.rb

Constant Summary

Constants included from FedoraLens

FedoraLens::HOST, FedoraLens::VERSION

Class Method Summary collapse

Methods included from FedoraLens::Lenses

as_dom, at_css, compose, empty_property, get_predicate, hash_update, literal_to_string, literals_to_strings, load_model, load_or_build_orm, orm_to_hash, single, uris_to_ids, zip

Methods included from FedoraLens

base_path, base_path=, connection, host, id_to_uri, uri_to_id

Class Method Details

.custom_lens(type) ⇒ Object


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
# File 'lib/test_class.rb', line 6

def self.custom_lens(type)
  Lens[
    get: lambda do |doc|
      if node = doc.at_css("relationship[type=#{type}]")
        node.content
      else
        ""
      end
    end,
    put: lambda do |doc, value|
      # TODO: create missing nodes
      # doc.at_css(selector).content = value; doc
      doc << Nokogiri::XML::Node.new("relationships", doc) if doc.root.nil?
      root = doc.root
      relationship = root.at_css("relationship[type=#{type}]")
      if relationship.nil?
        relationship = Nokogiri::XML::Node.new("relationship", doc)
        relationship.set_attribute("type", type)
        root << relationship
      end
      relationship.content = value
      doc
    end,
    create: lambda do |value|
      Nokogiri::XML("<relationships>
        <relationship type=\"#{type}\">#{value}</relationship>
      </relationships>")
    end
  ]
end