Skip to content
Browse files

Added the individual parser and got tests to pass

  • Loading branch information...
1 parent a309e0f commit df0623d0c95f8f4f656ec62c17c43b034f58b4df @justincbeck committed
View
6 .rvmrc
@@ -1,6 +1,6 @@
-if [[ -d "$rvm_path/environments" && -s "$rvm_path/environments/ruby-1.9.2-p136@gedcom_parser" ]] ; then
- \. "$rvm_path/environments/ruby-1.9.2-p136@gedcom_parser"
+if [[ -d "$rvm_path/environments" && -s "$rvm_path/environments/ruby-1.9.2-p290@gedcom_parser" ]] ; then
+ \. "$rvm_path/environments/ruby-1.9.2-p290@gedcom_parser"
else
- rvm --create use "ruby-1.9.2-p136@gedcom_parser"
+ rvm --create use "ruby-1.9.2-p290@gedcom_parser"
fi
View
3 Gemfile
@@ -1,4 +1,5 @@
source 'http://rubygems.org'
gem 'rspec'
-gem 'builder'
+gem 'builder'
+gem 'rubygems-update'
View
2 Gemfile.lock
@@ -11,6 +11,7 @@ GEM
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
+ rubygems-update (1.8.10)
PLATFORMS
ruby
@@ -18,3 +19,4 @@ PLATFORMS
DEPENDENCIES
builder
rspec
+ rubygems-update
View
14 lib/gedcom_processor/individual_parser.rb
@@ -1,12 +1,18 @@
require 'builder'
module GedcomProcessor
- class IndividualParser < Parser
- def parse(input, out)
- builder = Builder::XmlMarkup.new
+ class IndividualParser
+ def initialize(output)
+ @output = output
+ end
- while line = input.gets
+ def parse(component)
+ builder = Builder::XmlMarkup.new
+ component.each do |line|
+ line.each do |element|
+ @output.puts element
+ end
end
end
end
View
28 lib/gedcom_processor/parser.rb
@@ -1,12 +1,38 @@
module GedcomProcessor
class Parser
+
def initialize(output)
@output = output
+ @components = Array.new
+ @elements = Array.new
end
def parse(in_file, out_file)
+ depth = 0
+ component = Array.new
in_file.each_line do |line|
- out_file.write(line)
+ segments = line.split
+ if segments[0] == 0
+ xml = parse_component(component)
+ out_file.write(xml)
+ component = Array.new
+ end
+
+ component << segments
+
+ end
+ end
+
+ private
+
+ def parse_component(component)
+ type = component[0][1]
+ case type
+ when "INDI"
+ c_parser = IndividualParser.new
+ c_parser.parse component
+ else
+ raise Exception.new "Not yet implemented"
end
end
end
View
23 lib/gedcom_processor/stack.rb
@@ -1,23 +0,0 @@
-module GedcomProcessor
- class Stack
- def initialize
- @stack = []
- end
-
- def push(item)
- @stack[@stack.length] = item
- end
-
- def pop
- @stack.delete(@stack.last)
- end
-
- def peek
- @stack.last
- end
-
- def count
- @stack.length
- end
- end
-end
View
10 output/valid_family.xml
@@ -1,10 +0,0 @@
-0 @F9@ FAM
-1 HUSB @I62@
-1 WIFE @I63@
-1 CHIL @I64@
-1 CHIL @I70@
-1 CHIL @I77@
-1 MARR
-2 DATE Thursday, 29th November 1934
-2 PLAC Westminster,Abbey,London,England
-1 RIN 101
View
47 output/valid_head.xml
@@ -1,47 +0,0 @@
-0 HEAD
-1 SOUR PAF 2.2
-1 DEST PAF
-1 DATE Friday, 20th November 1992
-1 FILE ROYALS.GED
-1 CHAR ANSEL
-1 GEDC
-2 VERS 5.5
-2 FORM LINEAGE-LINKED
-1 SUBM @SUBM1@
-1 NOTE This Gedcom file should only be used as part of the testsuite
-2 CONC for Gedcom.pm (http://www.pjcj.net). I have removed a
-2 CONC lot of data from the original, and changed a few bits, so you
-2 CONC should use the original if you want royal genealogy. Contact me
-2 CONC if you cannot locate the original.
-2 CONC
-2 CONC Paul Johnson (pjcj@cpan.org)
-2 CONC
-2 CONC >> In a message to Cliff Manis (cmanis@csoftec.csf.com)
-2 CONC >> Denis Reid wrote the following:
-2 CONC >> Date: Fri, 25 Dec 92 14:12:32 -0500
-2 CONC >> From: ah189@cleveland.Freenet.Edu (Denis Reid)
-2 CONC >> Subject: THE ROYALS
-2 CONC >> First of all, MERRY CHRISTMAS!
-2 CONC >>
-2 CONC >> You may make this Royal GEDCOM available available to whomever.
-2 CONC >> As you know this is a work in process and have received
-2 CONC >> suggestions, corrections and additions from all over the planet...
-2 CONC >> some even who claim to be descended from Charlemange, himself!
-2 CONC >>
-2 CONC >> The weakest part of the Royals is in the French and Spanish lines.
-2 CONC >> I found that many of the French Kings had multiple mistresses
-2 CONC >> whose descendants claimed noble titles, and the Throne itself in
-2 CONC >> some cases. I have had the hardest time finding good published
-2 CONC >> sources for French and Spanish Royalty.
-2 CONC >>
-2 CONC >> If you do post it to a BBS or send it around, I would appreciate
-2 CONC >> it if you'd append a message to the effect that I would welcome
-2 CONC >> comments and suggestions and possible sources to improve the
-2 CONC >> database.
-2 CONC >>
-2 CONC >> Since the Royals had so many names and many titles it was
-2 CONC >> difficult to "fill in the blanks" with their name. In the
-2 CONC >> previous version, I included all their titles, names, monikers in
-2 CONC >> the notes.
-2 CONC >>
-2 CONC >> Thanks for your interest. Denis Reid
View
16 output/valid_individual.xml
@@ -1,16 +0,0 @@
-0 @I1@ INDI
-1 NAME Edward_VII /Wettin/
-1 TITL King of England
-1 SEX M
-1 BIRT
-2 DATE Tuesday, 9th November 1841
-2 PLAC Buckingham,Palace,London,England
-1 DEAT
-2 DATE Friday, 6th May 1910
-2 PLAC Buckingham,Palace,London,England
-1 BURI
-2 DATE Friday, 20th May 1910
-2 PLAC Windsor,Berkshire,England
-1 FAMS @F2@
-1 FAMC @F1@
-1 RIN 2
View
7 output/valid_submitter.xml
@@ -1,7 +0,0 @@
-0 @SUBM1@ SUBM
-1 NAME Denis R. Reid
-1 ADDR 149 Kimrose Lane
-2 CONT Broadview Heights, Ohio 44147-1258
-2 CONT Internet Email address: ah189@cleveland.freenet.edu
-1 PHON (216) 237-5364
-1 RIN 1
View
8 spec/gedcom_processor/individual_parser_spec.rb
@@ -7,9 +7,13 @@ module GedcomProcessor
it "should parse an individual defined in Gedcom and produce valid XML" do
in_file = File.join(File.dirname(__FILE__), '../', 'spec_data', "valid_individual.ged")
- out_file = File.join(File.dirname(__FILE__), '../../', 'output', "valid_individual.xml")
- parser.parse(File.new(in_file), File.new(out_file))
+ component = Array.new
+ in_file.each_line do |line|
+ component << line.split
+ end
+
+ parser.parse(component)
end
end
end
View
51 spec/gedcom_processor/stack_spec.rb
@@ -1,51 +0,0 @@
-require 'spec_helper'
-
-module GedcomProcessor
- describe Stack do
- let(:stack) { Stack.new }
-
- it "should return nil when pop is called and the stack is empty" do
- stack.pop.should == nil
- end
-
- it "should return true when an item is pushed on to the stack" do
- stack.push(3).should == 3
- end
-
- it "should return a count that equals the size of the stack" do
- stack.push(3)
- stack.count.should == 1
- end
-
- it "should return the poped item when pop is called and the stack is not empty" do
- stack.push(3)
- stack.pop.should == 3
- end
-
- it "should have one less item when pop is called and the stack is not empty" do
- stack.push(3)
- stack.count.should == 1
- stack.pop.should == 3
- stack.count.should == 0
- end
-
- it "should return a size of 0 when the stack is empty" do
- stack.count.should == 0
- end
-
- it "should return the top item when peek is called and the stack is not empty" do
- stack.push(3)
- stack.peek.should == 3
- end
-
- it "should return nil when peek is called and the stack is empty" do
- stack.peek.should == nil
- end
-
- it "should still contain the top item after peek is called" do
- stack.push(3)
- stack.peek.should == 3
- stack.count.should == 1
- end
- end
-end

0 comments on commit df0623d

Please sign in to comment.
Something went wrong with that request. Please try again.