File: library.rb

package info (click to toggle)
ruby-roxml 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 800 kB
  • sloc: ruby: 4,133; xml: 1,013; makefile: 7
file content (40 lines) | stat: -rw-r--r-- 957 bytes parent folder | download | duplicates (5)
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
class Publisher
  include ROXML

  xml_accessor :name
  
  def initialize(name = nil)
    @name = name
  end
  
  def ==(other)
    name == other.name
  end
  
  # other important functionality
end

class Novel
  include ROXML

  xml_accessor :isbn, :from => "@ISBN" # attribute with name 'ISBN'
  xml_accessor :title
  xml_accessor :description, :cdata => true  # text node with cdata protection
  xml_accessor :author
  xml_accessor :publisher, :as => Publisher # singular object reference for illustrative purposes.
  
  def ==(other)
    self.class.roxml_attrs.map(&:accessor).all? {|attr| send(attr) == other.send(attr) }
  end
end

class Library
  include ROXML

  xml_accessor :name, :from => "NAME", :cdata => true
  xml_accessor :novels, :as => [Novel] # by default roxml searches for books for in <novel> children, then, if none are present, in ./novels/novel children
  
  def ==(other)
    name == other.name && novels == other.novels
  end
end