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

attribute[RW]

Hash that contains attributes of object

children[RW]

Array of children for object

data[RW]

Hash that contains data relevant to the object

indent_delimiter[RW]

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

new() click to toggle source

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(child) click to toggle source

Add child element into children array

# File lib/orgy/org_object.rb, line 44
def add_child child
  @children << child
end
clear_deadline() click to toggle source

Clear a deadline

# File lib/orgy/org_object.rb, line 115
def clear_deadline
  @attribute[:deadline] = nil
end
clear_schedule() click to toggle source

Unschedule element

# File lib/orgy/org_object.rb, line 97
def clear_schedule
  @attribute[:scheduled] = nil 
end
contains_children?() click to toggle source

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
deadline(org_timestamp) click to toggle source

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
deadline?() click to toggle source

Tests if deadline exists

# File lib/orgy/org_object.rb, line 120
def deadline?
  @attribute[:deadline] != nil
end
delete_child(child) click to toggle source

Delete child element that matches argument

# File lib/orgy/org_object.rb, line 49
def delete_child child
  @children.delete child
end
each(&block) click to toggle source

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_child() click to toggle source

Pop a child element into children array

# File lib/orgy/org_object.rb, line 59
def pop_child
  @children.pop
end
push_child(child) click to toggle source

Push a child element into children array

# File lib/orgy/org_object.rb, line 54
def push_child child 
  @children.push child
end
schedule(org_timestamp) click to toggle source

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
schedule?() click to toggle source

Tests if element is scheduled

# File lib/orgy/org_object.rb, line 102
def schedule?
  @attribute[:scheduled] != nil
end
to_s() click to toggle source

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

print_deadline() click to toggle source
print_schedule() click to toggle source
set_indent(num) click to toggle source

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