require 'rubygems' require 'nokogiri' require 'time' module Atomic class Workspace class << self def parse(data) workspace = new doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data) workspace_node = doc.xpath('//app:workspace', NAMESPACES).first workspace.title = workspace_node.xpath('atom:title', NAMESPACES).first.text workspace_node.xpath('app:collection', NAMESPACES).each do |collection_node| # puts "+++++++++\n" # puts collection_node.inspect # puts "=========\n" # puts collection_node.xpath('//app:collection', NAMESPACES) # puts "---------\n" workspace.collections << Collection.parse(collection_node) end workspace end end attr_accessor :title, :collections def initialize(params = {}) @title = params[:title] @collections = params[:collections] || [] end def to_hash { :title => @title, :collections => @collections.collect{ |collection| collection.to_hash } } end end class Collection class << self def parse(data) collection = new collection_node = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data).xpath('//app:collection', NAMESPACES).first # puts "*********" # puts collection_node # puts "*********" collection.href = collection_node['href'] collection.title = collection_node.xpath('atom:title', NAMESPACES).first.text collection end end attr_accessor :href, :title def initialize(params = {}) @href = params[:href] @title = params[:title] end def to_hash { :href => @href, :title => @title } end end class Service class << self def parse(data) service = new doc = data.kind_of?(Nokogiri::XML::Element) ? data : Nokogiri.XML(data) service_node = doc.xpath('//app:service', NAMESPACES).first service_node.xpath('app:workspace', NAMESPACES).each do |workspace_node| service.workspaces << Workspace.parse(workspace_node) end service end end attr_accessor :workspaces def initialize(params = {}) @workspaces = params[:workspaces] || [] end def to_hash { :workspaces => @workspaces.collect { |workspace| workspace.to_hash } } end end end