Sha256: e784ac3a609dae9c4ebb64f3f61f85c5fa597a36e8accdb1433c058aebf9e108

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

# -*- coding: utf-8 -*-
require "yaml"
require "pp"

class Org2Yaml
  attr_accessor :help_cont

  def initialize(file)
    @help_cont = {} #{ head: [File.basename(file, '.org')] }
    @head_sym = nil
    @conts = ""
    @short_stored = []
    org_to_yaml(File.readlines(file))
  end

  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

  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

  def org_to_yaml(lines)
    lines.each do |line|
      m = line.force_encoding(Encoding::UTF_8).match(/^(\*+) (.+)/u)
      if m
        next_cont m[2]
      else
        @conts << line
      end
    end
    next_cont "EOF"
  end
end

if $PROGRAM_NAME == __FILE__
  helps = OrgToYaml.new(ARGV[0])
  pp helps.help_cont
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
my_help-1.2.10 lib/my_help/org2yml.rb
my_help-1.2.9 lib/my_help/org2yml.rb
my_help-1.2.8 lib/my_help/org2yml.rb
my_help-1.2.7 lib/my_help/org2yml.rb
my_help-1.2.6 lib/my_help/org2yml.rb
my_help-1.2.5 lib/my_help/org2yml.rb
my_help-1.2.4p1 lib/my_help/org2yml.rb
my_help-1.2.4 lib/my_help/org2yml.rb
my_help-1.2.3 lib/my_help/org2yml.rb
my_help-1.2.2 lib/my_help/org2yml.rb
my_help-1.2 lib/my_help/org2yml.rb
my_help-1.1a lib/my_help/org2yml.rb
my_help-1.1 lib/my_help/org2yml.rb