orgy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "simplecov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ multi_json (1.0.4)
11
+ rake (0.9.2.2)
12
+ rspec (2.8.0)
13
+ rspec-core (~> 2.8.0)
14
+ rspec-expectations (~> 2.8.0)
15
+ rspec-mocks (~> 2.8.0)
16
+ rspec-core (2.8.0)
17
+ rspec-expectations (2.8.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.8.0)
20
+ simplecov (0.5.4)
21
+ multi_json (~> 1.0.3)
22
+ simplecov-html (~> 0.5.3)
23
+ simplecov-html (0.5.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.0.0)
30
+ jeweler (~> 1.6.4)
31
+ rspec (~> 2.8.0)
32
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Trevor Basinger
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ ORGY - ORG-mode and rubY
2
+ ===========
3
+
4
+ Orgy allows you to read and write org files as objects. This lets you easily manipulate your org file programatically and allows you to easily extend your org-mode (read: life) into other environments.
5
+
6
+ Features
7
+ --------
8
+
9
+ * Generates org files with:
10
+ - Headlines
11
+ - Bulleted lists
12
+ - Numbered lists
13
+ - Plain text
14
+ - Hyperlinks
15
+ - Time stamps (active and inactive)
16
+ - Time ranges
17
+ - And more coming
18
+
19
+ * Parses org files into objects
20
+ - Not yet implemented
21
+
22
+ Examples
23
+ --------
24
+
25
+ Create the objects:
26
+
27
+ header = Orgy::OrgHeadline.new("This is my first header\n")
28
+ bullet_list = Orgy::OrgBulletList.new
29
+ link = Orgy::OrgHyperlink.new("http://github.com","It's what's for breakfast")
30
+ org_string = Orgy::OrgString.new("I love ")
31
+ normal_string = "github "
32
+
33
+ Assign the objects
34
+
35
+ bullet_list.add_item org_string.to_s << normal_string
36
+ bullet_list.add_item link
37
+
38
+ header.push_child bullet_list # No children were harmed in the making of this object
39
+
40
+ Now we can print the object
41
+
42
+ header.to_s
43
+
44
+ This prints out
45
+
46
+ * This is my first header
47
+ - I love github
48
+ - [[http://github.com][It's what's for breakfast]]
49
+
50
+ Requirements
51
+ ------------
52
+
53
+ For Development:
54
+
55
+ * bundler
56
+ * jeweler -- https://github.com/technicalpickles/jeweler/pull/225
57
+ * rspec
58
+
59
+ For Release:
60
+
61
+ * none
62
+
63
+ Install
64
+ -------
65
+
66
+ To build from source
67
+
68
+ bundle install
69
+ rake install
70
+
71
+ or install from rubygems.org
72
+
73
+ gem install orgy
74
+
75
+ Author
76
+ ------
77
+
78
+ Original author: Trevor Basinger
79
+
80
+ License
81
+ -------
82
+
83
+ The MIT License
84
+
85
+ Copyright (c) 2012 Trevor Basinger
86
+
87
+ Permission is hereby granted, free of charge, to any person obtaining
88
+ a copy of this software and associated documentation files (the
89
+ 'Software'), to deal in the Software without restriction, including
90
+ without limitation the rights to use, copy, modify, merge, publish,
91
+ distribute, sublicense, and/or sell copies of the Software, and to
92
+ permit persons to whom the Software is furnished to do so, subject to
93
+ the following conditions:
94
+
95
+ The above copyright notice and this permission notice shall be
96
+ included in all copies or substantial portions of the Software.
97
+
98
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
99
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
100
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
101
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
102
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
103
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
104
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
105
+
106
+ Misc
107
+ ----
108
+ Version numbers are specified by the Semantic Versioning 2.0.0-rc.1 standards
109
+ http://semver.org
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "orgy"
18
+ gem.homepage = "http://github.com/TrevorBasinger/Orgy"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{CRUD library for org files}
21
+ gem.description = %Q{Orgy allows you to read and write files as objects. This lets you easily manipulate your org file programatically and allows you to easy extend your org-mode (read: life) into other environments}
22
+ gem.email = "trevor.basinger@gmail.com"
23
+ gem.authors = ["Trevor Basinger"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "test #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,21 @@
1
+ require Orgy.libpath(*%w{orgy org_data_container})
2
+
3
+ module Orgy
4
+ # ===OrgBulletList
5
+ # {Org-mode ordered lists}[http://orgmode.org/manual/Plain-lists.html#index-lists_002c-ordered-172]
6
+ # Creates a bulleted list of items
7
+ class OrgBulletList < Orgy::OrgDataContainer
8
+
9
+ # Iterates though the container's objects and prints a single dash before the contained element.
10
+ # Afterwards, it prints the child elements if any
11
+ def to_s
12
+ str = ""
13
+ @data[:container].each do | bullet_point |
14
+ @indent.times{ str << @indent_delimiter }
15
+ str << "- " << bullet_point.to_s << "\n"
16
+ end
17
+ str << super
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require Orgy.libpath(*%w{orgy org_object})
2
+
3
+ module Orgy
4
+ # ===OrgData
5
+ # All objects that exist primarily to express data and can coexist with other org elements should inherit from this
6
+ class OrgData < Orgy::OrgObject
7
+
8
+ def initialize
9
+ super()
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ require Orgy.libpath(*%w{orgy org_data})
2
+
3
+ module Orgy
4
+ # ===OrgDataContainer
5
+ # Allows an org element to contain other elements that are not treated like children
6
+ class OrgDataContainer < Orgy::OrgData
7
+
8
+ def initialize
9
+ super()
10
+ @data[:container] = Array.new
11
+ @data[:container?] = true
12
+ end
13
+
14
+ # Add an item to the container
15
+ def add_item item
16
+ @data[:container].push item.to_s
17
+ end
18
+
19
+ # Add an array of items to the container
20
+ def add_items item_arr
21
+ item_arr.each do | item |
22
+ add_item(item)
23
+ end
24
+ end
25
+
26
+ # Delete item at a container index
27
+ def delete_item_at num
28
+ @data[:container].delete_at(num)
29
+ end
30
+
31
+ # Delete item matching argument
32
+ def delete_item item
33
+ @data[:container].delete item
34
+ end
35
+
36
+ # Tests to see if the container is empty
37
+ def empty?
38
+ @data[:container].empty?
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ require Orgy.libpath(*%w[orgy org_data])
2
+
3
+ module Orgy
4
+ # ===OrgHeader
5
+ # {Org-mode headline}[http://orgmode.org/manual/Headlines.html#Headlines]
6
+ class OrgHeadline < Orgy::OrgData
7
+
8
+ # Takes one argument in the form of a string
9
+ def initialize( headline )
10
+ super()
11
+ @data = Hash.new
12
+ @data[:headline] = headline.to_s
13
+
14
+ @indent_delimiter = "*"
15
+ end
16
+
17
+ # Print headline and its children to a string
18
+ def to_s
19
+ str = ""
20
+ @indent.times{ str << @indent_delimiter }
21
+ str << ' ' << @data[:headline].to_s
22
+ str << super << "\n"
23
+ #if @indent == 1 then str << "\n" end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require Orgy.libpath(*%w{orgy org_data})
2
+
3
+ module Orgy
4
+ # ===OrgLink
5
+ # {Org-mode Hyperlinks}[http://orgmode.org/manual/Hyperlinks.html#Hyperlinks]
6
+ class OrgHyperlink < OrgData
7
+
8
+ attr_reader :data
9
+
10
+ # Takes two arguements. The first is the string representation of the url.
11
+ # The second is the label you wish to use.
12
+ def initialize( url, title )
13
+ super()
14
+ @data[:url] = url
15
+ @data[:title] = title
16
+ end
17
+
18
+ def to_s
19
+ "[[#{@data[:url].to_s}][#{@data[:title].to_s}]]" << super
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require Orgy.libpath(*%w{orgy org_data_container})
2
+
3
+ module Orgy
4
+ # ===OrgNumberList
5
+ # {Org-mode ordered lists}[http://orgmode.org/manual/Plain-lists.html#index-lists_002c-ordered-172]
6
+ # Creates a bulleted list of items
7
+ class OrgNumberList < Orgy::OrgDataContainer
8
+
9
+ # Iterates though the container's objects and prints a single dash before the contained element.
10
+ # Afterwards, it prints the child elements if any
11
+ def to_s
12
+ str = ""
13
+ len = @data[:container].length
14
+ x = 1
15
+ @data[:container].each do | number |
16
+ @indent.times{ str << @indent_delimiter }
17
+ str << "#{x}. " << number.to_s << "\n"
18
+ #if x < len then str << "\n" end
19
+ x = x + 1
20
+ end
21
+ str << super
22
+ end
23
+
24
+ end
25
+ end
26
+
@@ -0,0 +1,130 @@
1
+
2
+ module Orgy
3
+ # === OrgObject
4
+ # OrgObject provides a basic set of functionality for org-mode elements that define some sort of structure
5
+ # If any org-element is capable of having child elements, it should extend this class.
6
+ class OrgObject
7
+ include Enumerable
8
+
9
+ public
10
+
11
+ # Hash that contains data relevant to the object
12
+ attr_accessor :data
13
+
14
+ # Hash that contains attributes of object
15
+ attr_accessor :attribute
16
+
17
+ # Array of children for object
18
+ attr_accessor :children
19
+
20
+ # String containing the indent delimiter
21
+ # By default it is set to two spaces. However, you can change this to use tabs like so:
22
+ # OrgObject.indent_delimiter = "\t"
23
+ attr_accessor :indent_delimiter
24
+
25
+ # Create new instance of OrgObject
26
+ def initialize
27
+ @data = Hash.new
28
+ @clock = []
29
+ @children = []
30
+ @attribute = {
31
+ :type => self.class,
32
+ :clock => @clock
33
+ }
34
+
35
+ if self.class == Orgy::OrgObject then
36
+ @indent = 0
37
+ else
38
+ @indent = 1
39
+ end
40
+ @indent_delimiter = " "
41
+ end
42
+
43
+ # Add child element into children array
44
+ def add_child child
45
+ @children << child
46
+ end
47
+
48
+ # Delete child element that matches argument
49
+ def delete_child child
50
+ @children.delete child
51
+ end
52
+
53
+ # Push a child element into children array
54
+ def push_child child
55
+ @children.push child
56
+ end
57
+
58
+ # Pop a child element into children array
59
+ def pop_child
60
+ @children.pop
61
+ end
62
+
63
+ # Tests to see if self contains children
64
+ def contains_children?
65
+ if @children == nil then false else true end
66
+ end
67
+
68
+ # Iterates through each child in array.
69
+ # Also allows for current any object that extends OrgObject to be enumerable
70
+ def each(&block)
71
+ @children.each do | child |
72
+ block.call(child)
73
+ end
74
+ end
75
+
76
+ # Print children to string
77
+ def to_s
78
+ str = ""
79
+ @children.each do | child |
80
+ child.set_indent @indent+1
81
+ str << child.to_s
82
+ end
83
+ return str
84
+ end
85
+
86
+ # Schedule element for a time
87
+ def schedule org_timestamp
88
+ if not org_timestamp.class == Orgy::OrgTimeStamp then
89
+ raise ArgumentError, "Argument must be a kind of Orgy::OrgTimeStamp"
90
+ end
91
+ @attribute[:scheduled] = org_timestamp
92
+ end
93
+
94
+ # Unschedule element
95
+ def clear_schedule
96
+ @attribute[:scheduled] = nil
97
+ end
98
+
99
+ # Tests if element is scheduled
100
+ def schedule?
101
+ @attribute[:scheduled] != nil
102
+ end
103
+
104
+ # Mark a deadline on element
105
+ def deadline org_timestamp
106
+ if not org_timestamp.class == Orgy::OrgTimeStamp then
107
+ raise ArgumentError, "Argument must be a kind of Orgy::OrgTimeStamp"
108
+ end
109
+ @attribute[:deadline] = org_timestamp
110
+ end
111
+
112
+ # Clear a deadline
113
+ def clear_deadline
114
+ @attribute[:deadline] = nil
115
+ end
116
+
117
+ # Tests if deadline exists
118
+ def deadline?
119
+ @attribute[:deadline] != nil
120
+ end
121
+
122
+ protected
123
+ # Set intentation of an object
124
+ # It's probably best not to call this directly.
125
+ def set_indent num
126
+ @indent = num
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,23 @@
1
+ require Orgy.libpath(*%w{orgy org_data})
2
+
3
+ module Orgy
4
+ # === OrgString
5
+ # Contains any plain text data that will need to be passed into an object
6
+ #
7
+ # If you plan on a string containing any child elements in the org file you need to use this class.
8
+ # Otherwise, use a regular string
9
+ class OrgString < OrgData
10
+
11
+ # Takes a string
12
+ def initialize string
13
+ super()
14
+ @data[:string] = string.to_s
15
+ end
16
+
17
+ # Print the string and any child elements
18
+ def to_s
19
+ @data[:string].to_s << super
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,62 @@
1
+ require Orgy.libpath(*%w[orgy org_data])
2
+
3
+ module Orgy
4
+ # ===OrgTimeRange
5
+ # {org-mode time ranges}[http://orgmode.org/manual/Timestamps.html#index-ranges_002c-time-752]
6
+ # Contains two OrgTimeStamps and will print out as an org-mode date/time range.
7
+ class OrgTimeRange
8
+
9
+ # Requires two arguments. Argument one and two are the starting and ending dates respectively.
10
+ # Arguments must be kind of DateTime or Orgy::OrgTimeStamp
11
+ def initialize date_one, date_two
12
+
13
+ if date_one.class != Orgy::OrgTimeStamp then
14
+ if date_one.class != DateTime then
15
+ raise ArgumentError, "Argument must be a kind of Orgy::OrgTimeStamp or DateTime"
16
+ end
17
+ end
18
+
19
+ if date_two.class != Orgy::OrgTimeStamp then
20
+ if date_two.class != DateTime then
21
+ raise ArgumentError, "Argument must be a kind of Orgy::OrgTimeStamp or DateTime"
22
+ end
23
+ end
24
+
25
+ if date_one.class == DateTime then
26
+ date_one = Orgy::OrgTimeStamp.new date_one
27
+ end
28
+
29
+ if date_two.class == DateTime then
30
+ date_two = Orgy::OrgTimeStamp.new date_two
31
+ end
32
+
33
+ @data = Hash.new
34
+ @data[:starting_date] = date_one
35
+ @data[:ending_date] = date_two
36
+ end
37
+
38
+ # Tests to see if the range is active
39
+ def active?
40
+ @data[:starting_date].active? or @data[:ending_date].active?
41
+ end
42
+
43
+ # Declares the range as active
44
+ def active!
45
+ @data[:starting_date].active!
46
+ @data[:ending_date].active!
47
+ end
48
+
49
+ # Declares the range as inactive
50
+ def inactive!
51
+ @data[:starting_date].inactive!
52
+ @data[:ending_date].inactive!
53
+ end
54
+
55
+ # Prints range to string
56
+ def to_s
57
+ if active? then active! else inactive! end
58
+ @data[:starting_date].to_s << '--' << @data[:ending_date].to_s
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,89 @@
1
+ require Orgy.libpath(*%w[orgy org_data])
2
+
3
+ module Orgy
4
+ # ===OrgTimeStamp
5
+ # {org-mode time ranges}[http://orgmode.org/manual/Timestamps.html#index-ranges_002c-time-752]
6
+ # OrgTimeStamp2will print out as an org-mode date/time.
7
+ class OrgTimeStamp
8
+
9
+ def initialize date_time
10
+ if not date_time.class == DateTime then
11
+ raise ArgumentError, "Argument must be a kind of DateTime"
12
+ end
13
+ @data = Hash.new
14
+ @data[:date] = date_time
15
+ @active = false
16
+ @has_time = false
17
+ @repeating = false
18
+ @repeat = 'd'
19
+ @repeat_interval = 1
20
+ end
21
+
22
+ def active?
23
+ @active
24
+ end
25
+
26
+ def active!
27
+ @active = true
28
+ end
29
+
30
+ def inactive!
31
+ @active = false
32
+ end
33
+
34
+ def has_time?
35
+ @has_time
36
+ end
37
+
38
+ def toggle_time!
39
+ @has_time = !@has_time
40
+ end
41
+
42
+ def repeating?
43
+ @repeating
44
+ end
45
+
46
+ def toggle_repeat!
47
+ @repeating = !@repeating
48
+ end
49
+
50
+ def daily!
51
+ @repeat = 'd'
52
+ @repeating = true
53
+ end
54
+
55
+ def weekly!
56
+ @repeat = 'w'
57
+ @repeating = true
58
+ end
59
+
60
+ def monthly!
61
+ @repeat = 'm'
62
+ @repeating = true
63
+ end
64
+
65
+ def yearly!
66
+ @repeat = 'y'
67
+ @repeating = true
68
+ end
69
+
70
+ def repeat_interval! num=1
71
+ if num.class != Fixnum and num.class != Integer then
72
+ raise ArgumentError, "Repeat interval should be a integer value"
73
+ end
74
+ @repeat_interval = num
75
+ end
76
+
77
+ def to_s
78
+ date = @data[:date]
79
+ str = ""
80
+ if active? then str << '<' else str << '[' end
81
+ str << date.strftime("%F %a")
82
+ if has_time? then str << date.strftime(" %R") end
83
+ if repeating? then str << ' +' << @repeat_interval.to_s << @repeat end
84
+ if active? then str << '>' else str << ']' end
85
+ str
86
+ end
87
+
88
+ end
89
+ end
data/lib/orgy.rb ADDED
@@ -0,0 +1,60 @@
1
+
2
+ module Orgy
3
+
4
+ # :stopdoc:
5
+ LIBPATH = ::File.expand_path('..', __FILE__) + ::File::SEPARATOR
6
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
+ VERSION = ::File.read(PATH + 'VERSION').strip
8
+ # :startdoc:
9
+
10
+ # Returns the library path for the module. If any arguments are given,
11
+ # they will be joined to the end of the libray path using
12
+ # <tt>File.join</tt>.
13
+ #
14
+ def self.libpath( *args )
15
+ rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
16
+ if block_given?
17
+ begin
18
+ $LOAD_PATH.unshift LIBPATH
19
+ rv = yield
20
+ ensure
21
+ $LOAD_PATH.shift
22
+ end
23
+ end
24
+ return rv
25
+ end
26
+
27
+ # Returns the lpath for the module. If any arguments are given,
28
+ # they will be joined to the end of the path using
29
+ # <tt>File.join</tt>.
30
+ #
31
+ def self.path( *args )
32
+ rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
33
+ if block_given?
34
+ begin
35
+ $LOAD_PATH.unshift PATH
36
+ rv = yield
37
+ ensure
38
+ $LOAD_PATH.shift
39
+ end
40
+ end
41
+ return rv
42
+ end
43
+
44
+ # Utility method used to require all files ending in .rb that lie in the
45
+ # directory below this file that has the same name as the filename passed
46
+ # in. Optionally, a specific _directory_ name can be passed in such that
47
+ # the _filename_ does not have to be equivalent to the directory.
48
+ #
49
+ def self.require_all_libs_relative_to( fname, dir = nil )
50
+ dir ||= ::File.basename(fname, '.*')
51
+ search_me = ::File.expand_path(
52
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
53
+
54
+ Dir.glob(search_me).sort.each {|rb| require rb}
55
+ end
56
+
57
+ end # module Orgy
58
+
59
+ Orgy.require_all_libs_relative_to(__FILE__)
60
+
data/orgy.gemspec ADDED
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "orgy"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Trevor Basinger"]
12
+ s.date = "2012-02-08"
13
+ s.description = "Orgy allows you to read and write files as objects. This lets you easily manipulate your org file programatically and allows you to easy extend your org-mode (read: life) into other environments"
14
+ s.email = "trevor.basinger@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/orgy.rb",
29
+ "lib/orgy/org_bullet_list.rb",
30
+ "lib/orgy/org_data.rb",
31
+ "lib/orgy/org_data_container.rb",
32
+ "lib/orgy/org_headline.rb",
33
+ "lib/orgy/org_hyperlink.rb",
34
+ "lib/orgy/org_number_list.rb",
35
+ "lib/orgy/org_object.rb",
36
+ "lib/orgy/org_string.rb",
37
+ "lib/orgy/org_timerange.rb",
38
+ "lib/orgy/org_timestamp.rb",
39
+ "orgy.gemspec",
40
+ "spec/org_bullet_list_spec.rb",
41
+ "spec/org_data_spec.rb",
42
+ "spec/org_headline_spec.rb",
43
+ "spec/org_hyperlink_spec.rb",
44
+ "spec/org_number_list_spec.rb",
45
+ "spec/org_object_spec.rb",
46
+ "spec/org_string_spec.rb",
47
+ "spec/orgy_spec.rb",
48
+ "spec/spec_helper.rb",
49
+ "spec/timerange_spec.rb",
50
+ "spec/timestamp_spec.rb"
51
+ ]
52
+ s.homepage = "http://github.com/TrevorBasinger/Orgy"
53
+ s.licenses = ["MIT"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = "1.8.15"
56
+ s.summary = "CRUD library for org files"
57
+
58
+ if s.respond_to? :specification_version then
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
63
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
66
+ else
67
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
70
+ s.add_dependency(%q<simplecov>, [">= 0"])
71
+ end
72
+ else
73
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
74
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
75
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
76
+ s.add_dependency(%q<simplecov>, [">= 0"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Orgy::OrgBulletList do
4
+
5
+ it "initializes properly" do
6
+ Orgy::OrgBulletList.new.should be_kind_of Orgy::OrgBulletList
7
+ end
8
+
9
+ before(:each) do
10
+ @bullet = Orgy::OrgBulletList.new
11
+ end
12
+
13
+ it "knows it's empty" do
14
+ @bullet.empty?.should eql true
15
+ end
16
+
17
+ it "adds an item to array" do
18
+ expect {
19
+ @bullet.add_item Orgy::OrgString.new('this is a test')
20
+ }.should_not raise_error
21
+ end
22
+
23
+ it "deletes an item from array using index" do
24
+ @bullet.add_item Orgy::OrgString.new('this is a test')
25
+ @bullet.delete_item_at 0
26
+ @bullet.empty?.should eql true
27
+ end
28
+
29
+ it "deletes an item from array using item" do
30
+ item = Orgy::OrgString.new('this is a test')
31
+ @bullet.add_item item
32
+ @bullet.delete_item @bullet.data[:container].first
33
+ @bullet.empty?.should eql true
34
+ end
35
+
36
+ it "prints to string" do
37
+ @bullet.add_item Orgy::OrgString.new('this is a test')
38
+ @bullet.add_item Orgy::OrgString.new('this is a test1')
39
+ @bullet.add_item Orgy::OrgString.new('this is a test2')
40
+ #puts
41
+ #puts @bullet.to_s
42
+ #puts
43
+ @bullet.to_s.should be_kind_of String
44
+ end
45
+
46
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Orgy::OrgData do
4
+
5
+ it "initializes correctly" do
6
+ Orgy::OrgData.new.should be_kind_of Orgy::OrgData
7
+ end
8
+
9
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Orgy::OrgHyperlink do
4
+
5
+ before(:each) do
6
+ @link = Orgy::OrgHyperlink.new 'http://github.com', 'Github'
7
+ end
8
+
9
+ it "initializes correctly" do
10
+ @link.should be_kind_of Orgy::OrgHyperlink
11
+ end
12
+
13
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Orgy::OrgNumberList do
4
+
5
+ it "initializes properly" do
6
+ Orgy::OrgNumberList.new.should be_kind_of Orgy::OrgNumberList
7
+ end
8
+
9
+ before(:each) do
10
+ @number = Orgy::OrgNumberList.new
11
+ end
12
+
13
+ it "knows it's empty" do
14
+ @number.empty?.should eql true
15
+ end
16
+
17
+ it "adds an item to array" do
18
+ expect {
19
+ @number.add_item Orgy::OrgString.new('this is a test')
20
+ }.should_not raise_error
21
+ end
22
+
23
+ it "deletes an item from array using index" do
24
+ @number.add_item Orgy::OrgString.new('this is a test')
25
+ @number.delete_item_at 0
26
+ @number.empty?.should eql true
27
+ end
28
+
29
+ it "deletes an item from array using item" do
30
+ item = Orgy::OrgString.new('this is a test')
31
+ @number.add_item item
32
+ @number.delete_item @number.data[:container].first
33
+ @number.empty?.should eql true
34
+ end
35
+
36
+ it "prints to string" do
37
+ @number.add_item Orgy::OrgString.new('this is a test')
38
+ @number.add_item Orgy::OrgString.new('this is a test1')
39
+ @number.add_item Orgy::OrgString.new('this is a test2')
40
+ #puts
41
+ #puts @number.to_s
42
+ #puts
43
+ @number.to_s.should be_kind_of String
44
+ end
45
+
46
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe Orgy::OrgObject do
4
+
5
+ before(:each) do
6
+ @oo = Orgy::OrgObject.new
7
+ end
8
+
9
+ it "adds a child" do
10
+ @oo.add_child(Orgy::OrgObject.new)
11
+ @oo.children.length.should eql(1)
12
+ end
13
+
14
+ it "removes a child" do
15
+ child = Orgy::OrgObject.new
16
+ @oo.add_child(child)
17
+ @oo.delete_child(child)
18
+ @oo.children.length.should eql(0)
19
+ end
20
+
21
+ it "pushes a child" do
22
+ child = Orgy::OrgObject.new
23
+ @oo.push_child(child)
24
+ @oo.children.length.should eql(1)
25
+ end
26
+
27
+ it "pops a child" do
28
+ child = Orgy::OrgObject.new
29
+ @oo.push_child(child)
30
+ @oo.pop_child().should equal(child)
31
+ end
32
+
33
+ it "contains children" do
34
+ child = Orgy::OrgObject.new
35
+ @oo.push_child(child)
36
+ @oo.contains_children?.should eql(true)
37
+ end
38
+
39
+ it "iterates through each child" do
40
+ # Create Children
41
+ child = Orgy::OrgObject.new
42
+ child1 = Orgy::OrgObject.new
43
+ child2 = Orgy::OrgObject.new
44
+
45
+ # Add children
46
+ @oo.add_child child
47
+ @oo.add_child child1
48
+ @oo.add_child child2
49
+
50
+ x = 0
51
+ @oo.each do | child |
52
+ x = x + 1
53
+ end
54
+
55
+ x.should eql(3)
56
+ end
57
+
58
+ it "prints it's children to a string" do
59
+ # Create Children
60
+ child = Orgy::OrgObject.new
61
+ child1 = Orgy::OrgObject.new
62
+
63
+ @oo.push_child child
64
+ @oo.push_child child1
65
+
66
+ @oo.to_s.class.to_s.should eql 'String'
67
+ end
68
+
69
+ it "schedules an object" do
70
+ @oo.schedule Orgy::OrgTimeStamp.new( DateTime.now )
71
+ @oo.attribute[:scheduled].should_not eql nil
72
+ end
73
+
74
+ it "knows its scheduled" do
75
+ @oo.schedule Orgy::OrgTimeStamp.new( DateTime.now )
76
+ @oo.schedule?.should eql true
77
+ end
78
+
79
+ it "clears its schedule" do
80
+ @oo.schedule Orgy::OrgTimeStamp.new( DateTime.now )
81
+ @oo.clear_schedule
82
+ @oo.schedule?.should eql false
83
+ end
84
+
85
+ it "sets a deadline" do
86
+ @oo.deadline Orgy::OrgTimeStamp.new( DateTime.now )
87
+ @oo.attribute[:deadline].should_not eql nil
88
+ end
89
+
90
+ it "knows it has a deadline" do
91
+ @oo.deadline Orgy::OrgTimeStamp.new( DateTime.now )
92
+ @oo.deadline?.should eql true
93
+ end
94
+
95
+ it "clears the deadline" do
96
+ @oo.deadline Orgy::OrgTimeStamp.new( DateTime.now )
97
+ @oo.clear_deadline
98
+ @oo.deadline?.should_not eql true
99
+ end
100
+
101
+
102
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Orgy::OrgString do
4
+
5
+ it "intializes with a single string parameter" do
6
+ ostr = Orgy::OrgString.new 'This is a test'
7
+ ostr.should be_instance_of Orgy::OrgString
8
+ end
9
+
10
+ it "prints data to string" do
11
+ ostr = Orgy::OrgString.new 'This is a test'
12
+ ostr.to_s.should be_instance_of String
13
+ end
14
+
15
+ end
data/spec/orgy_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+
4
+ describe Orgy do
5
+
6
+
7
+ end
8
+
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'orgy'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ describe Orgy::OrgTimeRange do
5
+
6
+ it "doesn't initialize with incorrect parameters" do
7
+ date1 = DateTime.now
8
+ date2 = DateTime.parse('9th of Feb 2012')
9
+ expect {
10
+ Orgy::OrgTimeRange.new date1, date2
11
+ }.should_not raise_exception
12
+ expect {
13
+ Orgy::OrgTimeRange.new
14
+ }.should raise_exception
15
+ expect {
16
+ Orgy::OrgTimeRange.new 1, 2
17
+ }.should raise_exception
18
+ end
19
+
20
+ before(:each) do
21
+ date1 = DateTime.now
22
+ date2 = DateTime.parse('2012-02-09')
23
+ @range = Orgy::OrgTimeRange.new date1, date2
24
+ end
25
+
26
+ it "knows if it's active or not" do
27
+ @range.active?.should eql false
28
+ end
29
+
30
+ it "activates itself" do
31
+ @range.active!
32
+ @range.active?.should eql true
33
+ end
34
+
35
+ it "deactivates itself" do
36
+ @range.inactive!
37
+ @range.active?.should eql false
38
+ end
39
+
40
+ it "prints to a string" do
41
+ @range.to_s.class.should eql String
42
+ end
43
+
44
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'date'
3
+
4
+ describe Orgy::OrgTimeStamp do
5
+
6
+ it "does not initializes without a parameter" do
7
+ expect {
8
+ Orgy::OrgTimeStamp.new
9
+ }.should raise_exception
10
+ end
11
+
12
+ before(:each) do
13
+ date = DateTime.now
14
+ @ts = Orgy::OrgTimeStamp.new date
15
+ end
16
+
17
+ it "detects if it is active or not" do
18
+ @ts.active?.class.should eql FalseClass
19
+ end
20
+
21
+ it "sets itself as active" do
22
+ @ts.active!.class.should eql TrueClass
23
+ @ts.active?.class.should_not eql FalseClass
24
+ end
25
+
26
+ it "sets itself as inactive" do
27
+ @ts.inactive!.class.should eql FalseClass
28
+ @ts.active?.class.should_not eql TrueClass
29
+ end
30
+
31
+ it "detects if it has time" do
32
+ @ts.has_time?.class.should eql FalseClass
33
+ end
34
+
35
+ it "toggles the has_time value" do
36
+ @ts.toggle_time!.class.should eql TrueClass
37
+ @ts.has_time?.class.should_not eql FalseClass
38
+ end
39
+
40
+ it "writes to string" do
41
+ #@ts.active!
42
+ #@ts.toggle_time!
43
+ #@ts.weekly!
44
+ #@ts.repeat_interval! 3
45
+ #puts
46
+ #puts @ts.to_s
47
+ #puts
48
+ @ts.to_s.class.should eql String
49
+ end
50
+
51
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orgy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Trevor Basinger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70218975875360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70218975875360
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &70218975874860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70218975874860
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &70218975874380 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.6.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70218975874380
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &70218975873880 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70218975873880
58
+ description: ! 'Orgy allows you to read and write files as objects. This lets you
59
+ easily manipulate your org file programatically and allows you to easy extend your
60
+ org-mode (read: life) into other environments'
61
+ email: trevor.basinger@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files:
65
+ - LICENSE.txt
66
+ - README.md
67
+ files:
68
+ - .document
69
+ - .rspec
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - VERSION
76
+ - lib/orgy.rb
77
+ - lib/orgy/org_bullet_list.rb
78
+ - lib/orgy/org_data.rb
79
+ - lib/orgy/org_data_container.rb
80
+ - lib/orgy/org_headline.rb
81
+ - lib/orgy/org_hyperlink.rb
82
+ - lib/orgy/org_number_list.rb
83
+ - lib/orgy/org_object.rb
84
+ - lib/orgy/org_string.rb
85
+ - lib/orgy/org_timerange.rb
86
+ - lib/orgy/org_timestamp.rb
87
+ - orgy.gemspec
88
+ - spec/org_bullet_list_spec.rb
89
+ - spec/org_data_spec.rb
90
+ - spec/org_headline_spec.rb
91
+ - spec/org_hyperlink_spec.rb
92
+ - spec/org_number_list_spec.rb
93
+ - spec/org_object_spec.rb
94
+ - spec/org_string_spec.rb
95
+ - spec/orgy_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/timerange_spec.rb
98
+ - spec/timestamp_spec.rb
99
+ homepage: http://github.com/TrevorBasinger/Orgy
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: -3652451836549852934
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.15
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: CRUD library for org files
127
+ test_files: []