Class: OrgMode::Formatters::Textual

Inherits:
Object
  • Object
show all
Defined in:
lib/org_mode/formatters/textual.rb

Instance Method Summary collapse

Constructor Details

#initialize(org_file) ⇒ Textual

Returns a new instance of Textual.



7
8
9
# File 'lib/org_mode/formatters/textual.rb', line 7

def initialize(org_file)
  @org_file = org_file
end

Instance Method Details

#formatObject



11
12
13
14
15
# File 'lib/org_mode/formatters/textual.rb', line 11

def format
  [ @org_file.header,
    @org_file.nodes.map {|n| format_node(n)} * "\n",
    @org_file.footer ].reject(&:blank?) * "\n\n"
end

#format_content(node) ⇒ Object



26
27
28
29
30
# File 'lib/org_mode/formatters/textual.rb', line 26

def format_content(node)
  node.content.lines.map do |l|
    [" " * node.indent, l].join
  end.join
end

#format_date(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/org_mode/formatters/textual.rb', line 32

def format_date(node)
  date = if node.date_end_time
           "#{node.date_start_time.strftime('%Y-%m-%d %a %H:%M')}-#{node.date_end_time.strftime('%H:%M')}"
         elsif node.date_start_time
           "#{node.date_start_time.strftime('%Y-%m-%d %a %H:%M')}"
         elsif node.date
           "#{node.date.strftime('%Y-%m-%d %a')}"
         else
           nil
         end

  date ? "<#{date}>" : nil
end

#format_node(node) ⇒ Object



17
18
19
# File 'lib/org_mode/formatters/textual.rb', line 17

def format_node(node)
  [format_title(node), format_content(node)].reject(&:blank?) * "\n" 
end

#format_title(node) ⇒ Object



21
22
23
24
# File 'lib/org_mode/formatters/textual.rb', line 21

def format_title(node)
  stars = "*" * node.stars
  [stars, node.todo_state, format_date(node), node.title].reject(&:blank?) * ' '
end