Re: Final iteration lost?

Robert Klemme <[email protected]> Thu, 15 Aug 2019 17:10:25 +0200
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAM9pMnOXmqxkJ6jWH8WJrEJBoZ=hq86R7XA2o3CT9L0B8pqbnQ@mail.gmail.com>
On Thu, Aug 15, 2019 at 1:31 PM Leam Hall <[email protected]> wrote:

> Here's the current iteration of that section.


So it is not the final iteration? :P


> The Job class
>
initialization takes some data and sets other values to nil. This is due
> to some older jobs not having those data sections. The sections are
> always in order.
>
> ###
>
> data = Hash.new
> jobs_file = 'input/leamhall_jobs.txt'
> File.foreach(jobs_file) { |line|
>    line.chomp!.strip!
>    next if line.empty?
>    if line.end_with?(')')
>      data.clear
>      header_array  = line.split(',')
>      title         = header_array.shift
>      dates         = header_array.pop
>      start_date, end_date = set_dates(dates)
>      employer      = header_array.join(' ').strip!
>      data = {  start_date: start_date, end_date: end_date,
>                title: title, employer: employer }
>      current_job   = Job.new(data)
>      jobs << current_job
>    elsif current_job.blurb.nil?
>      current_job.blurb = line
>    elsif current_job.tech.nil?
>      current_job.tech  = line
>    else
>      current_job.extra = line
>    end
> }
>

I would definitively move parsing of the header line and creation of a new
job into a separate function. Makes the line - section logic much more
readable.

Kind regards

robert

-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can -
without end}
http://blog.rubybestpractices.com/


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>