class OrgToYaml

Attributes

help_cont[RW]

Public Class Methods

new(file) click to toggle source
# File lib/my_help/org2yml.rb, line 7
def initialize(file)
  @help_cont = {} #{ head: [File.basename(file, '.org')] }
  @head_sym = nil
  @conts = ''
  @short_stored = []
  org_to_yaml(File.readlines(file))
end

Public Instance Methods

make_options(line) click to toggle source
# File lib/my_help/org2yml.rb, line 15
def make_options(line)
  head, desc = line.split(':')
  desc ||= head.to_s
  short = "-#{head[0]}"
  if @short_stored.include?(short) or head=='license' or head=='head'
    short = ''
  else
    @short_stored << short
  end
  { short: short, long: "#{head}", desc: desc }
end
next_cont(head) click to toggle source
# File lib/my_help/org2yml.rb, line 27
def next_cont(head)
  @help_cont[@head_sym][:cont] = @conts if @head_sym
  return if head == 'EOF'
  @conts = ''
  @head_sym = head.to_sym
  @help_cont[@head_sym] = {
    opts: make_options(head), title: head, cont: ''
  }
end
org_to_yaml(lines) click to toggle source
# File lib/my_help/org2yml.rb, line 37
def org_to_yaml(lines)
  lines.each do |line|
    m = line.force_encoding(Encoding::UTF_8).match(/^\* (.+)/u)
    if m
      next_cont m[1]
    else
      @conts << line
    end
  end
  next_cont 'EOF'
end