Class: GoApiClient::Parsers::Job

Inherits:
Helper
  • Object
show all
Defined in:
lib/go_api_client/parsers/job_parser.rb

Constant Summary collapse

PROPERTIES =
{
    :duration => :cruise_job_duration,
    :result => :cruise_job_result,
    :scheduled => :cruise_timestamp_01_scheduled,
    :assigned => :cruise_timestamp_02_assigned,
    :preparing => :cruise_timestamp_03_preparing,
    :building => :cruise_timestamp_04_building,
    :completing => :cruise_timestamp_05_completing,
    :completed => :cruise_timestamp_06_completed,
}

Class Method Summary collapse

Methods inherited from Helper

href_from

Class Method Details

.parse(root) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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