Sha256: cda524d836da9aa851d6a526c1c09f2e5d60682308e08a5da95159ed73ace915

Contents?: true

Size: 997 Bytes

Versions: 2

Compression:

Stored size: 997 Bytes

Contents

require 'plist'
require 'rjobs/command_builder'
require 'colorize'

module Rjobs
  class Job
    attr_accessor :id, :name, :status
    attr_writer :params, :command

    def initialize(id=0,xml="")
      @id = id
      parse(xml)
      @params= {}
      @command = ""
    end
    
    def xml=(xml)
      parse(xml)
    end

    def command
      cb = Rjobs::CommandBuilder.new(@command,@params)
      cb.build
    end
    
    def status_with_color
      case @status
      when /Finished/
        @status.green
      when /Running/
        @status.blue
      when /Failed/
        @status.light_red
      when /Not Exist/
        @status.red
      else
        @status
      end
    end


    private
    def parse(xml)
      return if xml.empty?
      result = Plist::parse_xml(xml)
      @name = result['jobAttributes'].nil? ? "" : result['jobAttributes']['name']      
      @status = result['jobAttributes'].nil? ? "Not Exist" : result['jobAttributes']['jobStatus']      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rjobs-0.3.3.alpha lib/rjobs/job.rb
rjobs-0.3.2.alpha lib/rjobs/job.rb