Class: OrgToYaml
- Inherits:
-
Object
- Object
- OrgToYaml
- Defined in:
- lib/my_help/org2yml.rb
Instance Attribute Summary collapse
-
#help_cont ⇒ Object
Returns the value of attribute help_cont.
Instance Method Summary collapse
-
#initialize(file) ⇒ OrgToYaml
constructor
A new instance of OrgToYaml.
- #make_options(line) ⇒ Object
- #next_cont(head) ⇒ Object
- #org_to_yaml(lines) ⇒ Object
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_cont ⇒ Object
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 (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: (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 |