class Orgy::OrgObject
OrgObject
¶ ↑
OrgObject
provides a basic set of functionality for org-mode elements that define some sort of structure If any org-element is capable of having child elements, it should extend this class.
Attributes
Hash that contains attributes of object
Array of children for object
Hash that contains data relevant to the object
String containing the indent delimiter By default it is set to two spaces. However, you can change this to use tabs like so:
OrgObject.indent_delimiter = "\t"
Public Class Methods
Create new instance of OrgObject
# File lib/orgy/org_object.rb, line 26 def initialize @data = Hash.new @clock = [] @children = [] @attribute = { :type => self.class, :clock => @clock } if self.class == Orgy::OrgObject then @indent = 0 else @indent = 1 end @indent_delimiter = " " end
Public Instance Methods
Add child element into children array
# File lib/orgy/org_object.rb, line 44 def add_child child @children << child end
Clear a deadline
# File lib/orgy/org_object.rb, line 115 def clear_deadline @attribute[:deadline] = nil end
Unschedule element
# File lib/orgy/org_object.rb, line 97 def clear_schedule @attribute[:scheduled] = nil end
Tests to see if self contains children
# File lib/orgy/org_object.rb, line 64 def contains_children? if @children == nil then false else true end end
Mark a deadline on element
# File lib/orgy/org_object.rb, line 107 def deadline org_timestamp if not org_timestamp.class == Orgy::OrgTimeStamp then raise ArgumentError, "Argument must be a kind of Orgy::OrgTimeStamp" end @attribute[:deadline] = org_timestamp end
Tests if deadline exists
# File lib/orgy/org_object.rb, line 120 def deadline? @attribute[:deadline] != nil end
Delete child element that matches argument
# File lib/orgy/org_object.rb, line 49 def delete_child child @children.delete child end
Iterates through each child in array. Also allows for current any object that extends OrgObject
to be enumerable
# File lib/orgy/org_object.rb, line 70 def each(&block) @children.each do | child | block.call(child) end end
Pop a child element into children array
# File lib/orgy/org_object.rb, line 59 def pop_child @children.pop end
Push a child element into children array
# File lib/orgy/org_object.rb, line 54 def push_child child @children.push child end
Schedule element for a time
# File lib/orgy/org_object.rb, line 89 def schedule org_timestamp if not org_timestamp.class == Orgy::OrgTimeStamp then raise ArgumentError, "Argument must be a kind of Orgy::OrgTimeStamp" end @attribute[:scheduled] = org_timestamp end
Tests if element is scheduled
# File lib/orgy/org_object.rb, line 102 def schedule? @attribute[:scheduled] != nil end
Print children to string
# File lib/orgy/org_object.rb, line 77 def to_s str = "" if schedule? then str << "\n" << print_schedule end if deadline? then str << "\n" << print_deadline end @children.each do | child | child.set_indent @indent+1 str << child.to_s end return str end
Protected Instance Methods
# File lib/orgy/org_object.rb, line 139 def print_deadline str = "" if deadline? then str << 'DEADLINE: ' << @attribute[:deadline].to_s << "\n" end str end
# File lib/orgy/org_object.rb, line 131 def print_schedule str = "" if schedule? then str << 'SCHEDULED: ' << @attribute[:scheduled].to_s << "\n" end str end
Set intentation of an object It’s probably best not to call this directly.
# File lib/orgy/org_object.rb, line 127 def set_indent num @indent = num end