Class: Atomic::Atompub::Service
- Inherits:
-
Object
- Object
- Atomic::Atompub::Service
- Includes:
- Parser
- Defined in:
- lib/atomic/atompub.rb
Instance Attribute Summary collapse
-
#workspaces ⇒ Object
Returns the value of attribute workspaces.
Instance Method Summary collapse
- #handle_close_element(node) ⇒ Object
- #handle_open_element(node, reader) ⇒ Object
-
#initialize(params = {}) ⇒ Service
constructor
A new instance of Service.
- #to_hash ⇒ Object
- #to_xml(as_document = true, target = nil) ⇒ Object
Methods included from Parser
Constructor Details
#initialize(params = {}) ⇒ Service
Returns a new instance of Service.
158 159 160 161 162 |
# File 'lib/atomic/atompub.rb', line 158 def initialize(params = {}) params.symbolize_keys! params.assert_valid_keys(:workspaces) self.workspaces = params[:workspaces] || [] end |
Instance Attribute Details
#workspaces ⇒ Object
Returns the value of attribute workspaces.
156 157 158 |
# File 'lib/atomic/atompub.rb', line 156 def workspaces @workspaces end |
Instance Method Details
#handle_close_element(node) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/atomic/atompub.rb', line 177 def handle_close_element(node) case [node.depth, node.uri, node.name] when [0, NS_APP, 'service'] when [1, NS_APP, 'workspace'] else puts("Service ==> Unexpected Close Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect} #{node.text}") end end |
#handle_open_element(node, reader) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/atomic/atompub.rb', line 164 def handle_open_element(node, reader) progressed = false case [node.depth, node.uri, node.name] when [0, NS_APP, 'service'] when [1, NS_APP, 'workspace'] self.workspaces << Workspace.new.deserialize(reader) progressed = true else puts("Service ==> Unexpected Open Element - [#{node.depth}] #{node.name} {#{node.uri}} #{node.attributes.inspect}") end return progressed end |
#to_hash ⇒ Object
186 187 188 189 190 |
# File 'lib/atomic/atompub.rb', line 186 def to_hash { :workspaces => self.workspaces.collect { |workspace| workspace.to_hash } } end |
#to_xml(as_document = true, target = nil) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/atomic/atompub.rb', line 192 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(:service, nsdec) do self.workspaces.each do |workspace| workspace.to_xml(false, xml) end end xml.target! end |