Class: Atomic::Atompub::Service

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/atomic/atompub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#deserialize, included

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

#workspacesObject

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_hashObject



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