Sha256: bb7fd21f8361ad191232a7a0f9f645d09000a2243e926b3800d44bdb3e62e5fe

Contents?: true

Size: 729 Bytes

Versions: 3

Compression:

Stored size: 729 Bytes

Contents

class List
  attr_accessor :name, :body, :steps

  def initialize(file)
    fname = File.basename(file)
    @name = fname.sub(File.extname(fname), '')
    @body = File.read(file)
    @steps = parse_steps(@body)
  end

  private

  def parse_steps(body)
    steps = []
    current_step = nil
    body.lines.each do |line|
      next if line.strip.empty?
      if line =~ /^-/
        current_name = line.sub(/^-/,'').strip
        current_step = Step.new(current_name)
        steps << current_step
      elsif current_step
        current_step.body << line
      end
    end
    steps
  end

  class Step
    attr_accessor :name, :body

    def initialize(name, body = '')
      @name = name
      @body = body
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
checkcheckit-0.0.3 lib/checkcheckit/list.rb
checkcheckit-0.0.2 lib/checkcheckit/list.rb
checkcheckit-0.0.1 lib/checkcheckit/list.rb