class GoApiClient::Parsers::Job

Constants

PROPERTIES

Public Class Methods

parse(root) click to toggle source
# File lib/go_api_client/parsers/job_parser.rb, line 19
def parse(root)
  artifacts_uri = root.xpath('./artifacts').first.attributes['baseUri'].value
  attributes = {
      :artifacts_uri => artifacts_uri,
      :self_uri => href_from(root.xpath("./link[@rel='self']")),
      :id => root.xpath('./id').first.content,
      :name => root.attributes['name'].value,
      :parsed_artifacts => root.xpath('./artifacts/artifact').collect do |artifact_element|
        GoApiClient::Parsers::Artifact.parse(artifacts_uri, artifact_element)
      end
  }

  PROPERTIES.each do |variable, property_name|
    property_value = root.xpath("./properties/property[@name='#{property_name}']").first.content rescue nil
    next if property_value.nil? || property_value.empty?
    if property_name =~ /timestamp/
      property_value = Time.parse(property_value).utc
    elsif property_value =~ /^\d+$/
      property_value = property_value.to_i
    end
    attributes = {variable => property_value}.merge(attributes)
  end

  GoApiClient::Domain::Job.new(attributes)
end