Class: Atomic::Atompub::Workspace
- Inherits:
-
Object
- Object
- Atomic::Atompub::Workspace
- Includes:
- Parser
- Defined in:
- lib/atomic/atompub.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #handle_close_element(node) ⇒ Object
- #handle_open_element(node, reader) ⇒ Object
-
#initialize(params = {}) ⇒ Workspace
constructor
A new instance of Workspace.
- #to_hash ⇒ Object
- #to_xml(as_document = true, target = nil) ⇒ Object
Methods included from Parser
Constructor Details
#initialize(params = {}) ⇒ Workspace
Returns a new instance of Workspace.
98 99 100 101 102 103 |
# File 'lib/atomic/atompub.rb', line 98 def initialize(params = {}) params.symbolize_keys! params.assert_valid_keys(:title, :collections) self.title = params[:title] self.collections = params[:collections] || [] end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
96 97 98 |
# File 'lib/atomic/atompub.rb', line 96 def collections @collections end |
#title ⇒ Object
Returns the value of attribute title.
96 97 98 |
# File 'lib/atomic/atompub.rb', line 96 def title @title end |
Instance Method Details
#handle_close_element(node) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/atomic/atompub.rb', line 119 def handle_close_element(node) case [node.depth, node.uri, node.name] when [0, NS_APP, 'workspace'] when [1, NS_ATOM, 'title'] self.title = node.text when [1, NS_APP, 'collection'] else puts("Workspace ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}") end end |
#handle_open_element(node, reader) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/atomic/atompub.rb', line 105 def handle_open_element(node, reader) progressed = false case [node.depth, node.uri, node.name] when [0, NS_APP, 'workspace'] when [1, NS_ATOM, 'title'] when [1, NS_APP, 'collection'] self.collections << Collection.new.deserialize(reader) progressed = true else puts("Workspace ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}") end return progressed end |
#to_hash ⇒ Object
130 131 132 133 134 135 |
# File 'lib/atomic/atompub.rb', line 130 def to_hash { :title => self.title, :collections => self.collections.collect{ |collection| collection.to_hash } } end |
#to_xml(as_document = true, target = nil) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/atomic/atompub.rb', line 137 def to_xml(as_document=true, target=nil) nsdec = as_document ? {:"xmlns:atom" => NS_ATOM, :"xmlns:app" => NS_APP} : {} xml = Builder::XmlMarkup.new(:target => target) xml.instruct! if as_document xml.app(:workspace, nsdec) do xml.atom(:title, self.title) self.collections.each do |collection| collection.to_xml(false, xml) end end xml.target! end |