Sha256: f75c3364c552db359315d4f87b1d47e71504a5d2bae5ef91b7c153e901751899
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
# -*- coding: utf-8 -*- require 'yaml' require 'pp' class OrgToYaml 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[1] 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
my_help-0.8.6 | lib/my_help/org2yml.rb |