Sha256: ae2b58050b388f44426d4c7b4c47988e8b4433ef197d129424fea4f5cfbcfa44

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

module Workflow

  def self.doc_parse_first_line(str)
    if str.match(/^([^\n]*)\n\n(.*)/sm)
      str.replace $2
      $1
    else
      ""
    end
  end

  def self.doc_parse_up_to(str, pattern, keep = false)
    pre, _pat, _post = str.partition pattern
    if _pat
      [pre, (keep ? _pat << _post : _post)]
    else
      _post
    end
  end

  def self.doc_parse_chunks(str, pattern)
    parts = str.split(pattern)
    return {} if parts.length < 2
    tasks = Hash[*parts[1..-1].collect{|v| v.strip}]
    tasks.delete_if{|t,d| d.empty?}
    tasks
  end

  def self.parse_workflow_doc(doc)
    title = doc_parse_first_line doc
    description, task_info = doc_parse_up_to doc, /^# Tasks/i
    task_description, tasks = doc_parse_up_to task_info, /^##/, true
    tasks = doc_parse_chunks tasks, /## (.*)/ 
    {:title => title.strip, :description => description.strip, :task_description => task_description.strip, :tasks => tasks}
  end

  def documentation_markdown
    file = @libdir['workflow.md'].find
    if file.exists?
      file.read
    else
      ""
    end
  end

  def load_documentation
    @documentation = Workflow.parse_workflow_doc documentation_markdown
    @documentation[:tasks].each do |task, description|
      tasks[task.to_sym].description = description
    end
  end

  attr_accessor :documentation
  def documentation
    load_documentation if @documentation.nil?
    @documentation 
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rbbt-util-5.9.1 lib/rbbt/workflow/doc.rb
rbbt-util-5.9.0 lib/rbbt/workflow/doc.rb
rbbt-util-5.8.10 lib/rbbt/workflow/doc.rb
rbbt-util-5.8.9 lib/rbbt/workflow/doc.rb
rbbt-util-5.8.8 lib/rbbt/workflow/doc.rb
rbbt-util-5.8.7 lib/rbbt/workflow/doc.rb
rbbt-util-5.8.6 lib/rbbt/workflow/doc.rb