Class: OrgToYaml

Inherits:
Object
  • Object
show all
Defined in:
lib/my_help/org2yml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ OrgToYaml

Returns a new instance of OrgToYaml.



8
9
10
11
12
13
14
# File 'lib/my_help/org2yml.rb', line 8

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

Instance Attribute Details

#help_contObject

Returns the value of attribute help_cont.



6
7
8
# File 'lib/my_help/org2yml.rb', line 6

def help_cont
  @help_cont
end

Instance Method Details

#make_options(line) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/my_help/org2yml.rb', line 16

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) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/my_help/org2yml.rb', line 28

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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/my_help/org2yml.rb', line 38

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