Class: OrgMode::Processors::ArchiveDone
- Inherits:
-
Object
- Object
- OrgMode::Processors::ArchiveDone
- Defined in:
- lib/org_mode/processors/archive_done.rb
Instance Method Summary collapse
-
#initialize(org_file) ⇒ ArchiveDone
constructor
A new instance of ArchiveDone.
- #process ⇒ Object
-
#walk_and_update_node_children(node, &block) ⇒ Object
Private: walks all nodes but updates children array with return value of called function.
Constructor Details
#initialize(org_file) ⇒ ArchiveDone
Returns a new instance of ArchiveDone.
37 38 39 |
# File 'lib/org_mode/processors/archive_done.rb', line 37 def initialize(org_file) @org_file = ArchiveDoneOrgFile.new(org_file) end |
Instance Method Details
#process ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/org_mode/processors/archive_done.rb', line 41 def process @org_file.create_archived_root_node unless @org_file.archived_root_node to_be_archived_trees = [] walk_and_update_node_children @org_file do |children| to_be_archived_trees << children.select(&:done?) children.reject(&:done?) end @org_file.archived_root_node.children.concat( to_be_archived_trees.flatten ) @org_file end |
#walk_and_update_node_children(node, &block) ⇒ Object
Private: walks all nodes but updates children array with return value of called function.
Can be used to extract nodes from tree
61 62 63 64 65 66 |
# File 'lib/org_mode/processors/archive_done.rb', line 61 def walk_and_update_node_children(node, &block) node.children = block.call(node.children) node.children.map do |n| walk_and_update_node_children(n, &block) end end |