Sha256: 7ce73d1518992eec3018da01a27587632b47e02af97bfdd6dfc66a09a841e5c2

Contents?: true

Size: 793 Bytes

Versions: 6

Compression:

Stored size: 793 Bytes

Contents

module Rjobs
  class JobsFile
    def initialize(jobs_file="")
      @job_ids = []
      @job_names = []

      unless jobs_file.empty?
        File.open(jobs_file, "r") do |infile|
          while (line = infile.gets)
            unless line.empty? 
              line =~ /(\w+)[\t\s](\d+)(\n)*/          
              @job_names << $1.to_s.strip
              @job_ids << $2.to_s.strip
            end         
          end
        end
      end
    end

    def ids
      @job_ids
    end
    
    def job_names
      @job_names
    end
    
    def list_all
      puts @job_ids.join("\n")
    end

    def write(file_name, jobs)

      File.open(file_name, 'w') { |f| 
        jobs.each do |job|
          f << job.name << "\t" << job.id << "\n"
        end
      }

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rjobs-0.3.3.alpha lib/rjobs/jobs_file.rb
rjobs-0.3.2.alpha lib/rjobs/jobs_file.rb
rjobs-0.3.1.alpha lib/rjobs/jobs_file.rb
rjobs-0.3.0.alpha lib/rjobs/jobs_file.rb
rjobs-0.2.0.alpha lib/rjobs/jobs_file.rb
rjobs-0.1.0.alpha lib/rjobs/jobs_file.rb