Skip to content

Commit

Permalink
Loads file and extracts headlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Dewey committed Dec 20, 2009
1 parent a3f2578 commit 913e56d
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 2 deletions.
27 changes: 27 additions & 0 deletions lib/orgmode_parser/headlines.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Orgmode

# Represents a headline in an orgmode file.
class Headline

This comment has been minimized.

Copy link
@eri-san

eri-san Sep 9, 2019

#62 [](url)


# This is the line
attr_reader :line

# This is the "level" of the headline
attr_reader :level

def initialize(line)
@line = line
if (@line =~ /^\*+/) then
@level = $&.length
else
raise "'#{line}' is not a valid headline"
end
end

# Determines if a line is an orgmode "headline":
# A headline begins with one or more asterisks.
def self.is_headline?(line)
line =~ /^\*+/
end
end # class Headline
end # class Orgmode
25 changes: 25 additions & 0 deletions lib/orgmode_parser/orgmode_load.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##
## Simple routines for loading / saving an ORG file.
##

module Orgmode

class Parser

# All of the lines of the orgmode file
attr_reader :lines

# All of the headlines in the org file
attr_reader :headlines

def initialize(fname)
@lines = IO.readlines(fname)
@headlines = Array.new
@lines.each do |line|
if (Headline.is_headline? line) then
@headlines << (Headline.new line)
end
end
end # self.new
end # class OrgmodeParser
end # module OrgmodeParser
53 changes: 53 additions & 0 deletions spec/data/remember.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
* New Ideas
** YAML header in Webby

Make sure you don't have TABS here. Best practice: Configure your
editor to use spaces instaed of tabs, and if you can see whitespace,
even better.

In emacs, set indent-tabs-mode to NIL.
** Ruby Gems behind Proxy

Set the following environment variable:

So, I added a User Variable for my account called http_proxy with
the value of http://<proxyserveraddress>:8080, rebooted, ran plan
old vanillia gem install rails –include-dependencies, and magically,
it worked
** Hyper-V technical info

http://technet.microsoft.com/en-us/dd565807.aspx
** VirtualBox

Virtualization software from Sun. Looks like it might be more for
dev/test. I'm surprised this hasn't popped at
all. http://www.virtualbox.org/. Backed by Sun.
** Interesting LaTeX article

http://nitens.org/taraborelli/latex -- on the virtues of LaTeX
** XEmacs / Emacs internals

Looks like an interesting resource if I want to learn how Emacs works.

http://www.xemacs.org/Documentation/21.5/html/internals_9.html#SEC19
** MikTeX

Get it here: http://www.miktex.org/portable/
** Orgmode publishing tutorial

[[http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.php][Publishing Org-mode files to HTML]]
** Git and Live Mesh

This is really helpful:
http://whereslou.com/2009/06/04/using-live-mesh-and-git-the-best-of-both-worlds
** VDI deployment stats

Key takeaways:
- 74% are using VDI in production or pilot ... but 45% of those using have less than 100 users
- Upward of 55% of the DAC members [project] they will have up to 50% of their users using VDI in 3 years (~1/2 of those will have > 50%)
- No real surprises on the reasons / benefits etc
- Interestingly ... even if TS supported all client apps / supported user-install apps - 100% of the DAC preferred VDI over TS
- Most companies said a portion of their users would have VDI as the primary replacement desktop (60% < 20% of users, 32% 21-50% of users)
** Hyper-V Scheduler Information

http://msdn.microsoft.com/en-us/library/bb969782.aspx
54 changes: 52 additions & 2 deletions spec/orgmode_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@

require File.join(File.dirname(__FILE__), %w[spec_helper])

describe OrgmodeParser do
describe Orgmode::Parser do
it "should open ORG files" do
parser = OrgmodeParser.new("foo.org")
parser = Orgmode::Parser.new("data/remember.org")
end

it "should fail on non-existant files" do
lambda { parser = Orgmode::Parser.new("does-not-exist.org") }.should raise_error
end

it "should load all of the lines" do
parser = Orgmode::Parser.new("data/remember.org")
parser.lines.length.should == 53
end

it "should find all headlines" do
parser = Orgmode::Parser.new("data/remember.org")
parser.should have(12).headlines
end

it "can find a headline by index" do
parser = Orgmode::Parser.new("data/remember.org")
parser.headlines[1].line.should == "** YAML header in Webby\n"
end

it "should determine headline levels" do
parser = Orgmode::Parser.new("data/remember.org")
parser.headlines[0].level.should == 1
parser.headlines[1].level.should == 2
end
end

describe Orgmode::Headline do

it "should recognize headlines that start with asterisks" do
Orgmode::Headline.is_headline?("*** test\n").should_not be_nil
end

it "should reject headlines without headlines at the start" do
Orgmode::Headline.is_headline?(" nope!").should be_nil
Orgmode::Headline.is_headline?(" tricked you!!!***").should be_nil
end

it "should reject improper initialization" do
lambda { Orgmode::Headline.new " tricked**" }.should raise_error
end

it "should properly determine headline level" do
samples = %w[*one **two ***three ****four]
expected = 1
samples.each do |sample|
h = Orgmode::Headline.new sample
h.level.should == expected
expected += 1
end
end
end

0 comments on commit 913e56d

Please sign in to comment.