Skip to content

Commit

Permalink
Added the individual parser and got tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
justincbeck committed Aug 27, 2011
1 parent a309e0f commit df0623d
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 165 deletions.
6 changes: 3 additions & 3 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -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

3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'http://rubygems.org'

gem 'rspec'
gem 'builder'
gem 'builder'
gem 'rubygems-update'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ GEM
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
rubygems-update (1.8.10)

PLATFORMS
ruby

DEPENDENCIES
builder
rspec
rubygems-update
14 changes: 10 additions & 4 deletions lib/gedcom_processor/individual_parser.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 27 additions & 1 deletion lib/gedcom_processor/parser.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 0 additions & 23 deletions lib/gedcom_processor/stack.rb

This file was deleted.

10 changes: 0 additions & 10 deletions output/valid_family.xml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 0 additions & 47 deletions output/valid_head.xml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions output/valid_individual.xml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions output/valid_submitter.xml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions spec/gedcom_processor/individual_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 0 additions & 51 deletions spec/gedcom_processor/stack_spec.rb

This file was deleted.

0 comments on commit df0623d

Please sign in to comment.