Skip to content

Commit 5a7726e

Browse files
author
Matthias Rabe
committed
also read OBJE and SOUR
Signed-off-by: Matthias Rabe <[email protected]>
1 parent 38c2fb1 commit 5a7726e

File tree

1 file changed

+86
-22
lines changed

1 file changed

+86
-22
lines changed

lib/ged_parse.inc.rb

+86-22
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ def get_cached_detail(sym, tag); raise "NOT AVAILABLE FOR NOTES"; end
209209
def fields; raise "NOT AVAILABLE FOR NOTES"; end
210210
end
211211

212+
class Object < GedSection
213+
attr_reader :name
214+
215+
def initialize(gid)
216+
super
217+
@name= gid
218+
@type= :object
219+
end
220+
221+
def fname; return get_cached_detail(:file, "FILE"); end
222+
def type; return get_cached_detail(:type, "FILE_FORM"); end
223+
def note; return get_cached_detail(:title, "FILE_TITL"); end
224+
end
225+
212226
class Place < GedSection
213227
attr_reader :name
214228

@@ -221,8 +235,18 @@ def initialize(gid)
221235
def objs; return get_details("OBJE"); end
222236
end
223237

238+
class Source < GedSection
239+
attr_reader :name
240+
241+
def initialize(gid)
242+
super
243+
@name= gid
244+
@type= :source
245+
end
246+
end
247+
224248
class Gedcom
225-
attr_reader :individuals, :families, :tags, :sections, :places, :sources
249+
attr_reader :individuals, :families, :notes, :objects, :sections, :places, :sources, :tags
226250

227251
def initialize(file_name)
228252
@file_name= file_name
@@ -233,9 +257,10 @@ def refresh
233257
@individuals= []
234258
@families= []
235259
@notes= []
260+
@objects= []
236261
@sections= []
237262
@places= []
238-
@sources= [] #TODO
263+
@sources= []
239264
@tags= []
240265

241266
f= File.new(@file_name, 'r')
@@ -251,31 +276,31 @@ def refresh
251276
section_type= ""
252277
section= nil
253278

254-
place_section= nil
255-
place_level= nil
256-
place_level_higher= false
279+
object_section, object_level = nil, nil, false
280+
place_section, place_level, place_level_higher= nil, nil, false
257281

258282
f.each do |gedline|
259-
260283
level, tag, rest= gedline.chop.split(' ', 3)
261284

262285
if level.to_i == 0
263-
place_section= nil
264-
place_level= nil
265-
place_level_higher= false
286+
object_section = nil
287+
place_section = nil
266288

267289
# push the last section
268290
case section_type
269291
when "" then 1
270292
when "INDI" then @individuals.push section if section
271293
when "FAM" then @families.push section if section
272294
when "NOTE" then @notes.push section if section
295+
when "OBJE" then @objects.push section if section
296+
when "SOUR" then @sources.push section if section
273297
else
274298
@sections.push section if section
275299
end
276300

277301
#start a new section
278-
case rest.to_s.chomp
302+
type= rest.to_s.chomp
303+
case type
279304
when "INDI"
280305
#create an individual
281306
section= Individual.new(tag)
@@ -284,47 +309,76 @@ def refresh
284309
#create a family
285310
section= Family.new(tag)
286311
section_type= 'FAM'
312+
when "OBJE"
313+
#create an object
314+
section= Object.new(tag)
315+
section_type= 'OBJE'
316+
when "SOUR"
317+
#create a source
318+
section= Source.new(tag)
319+
section_type= 'SOUR'
287320
else
288321
#create a general section
289322
if not rest.nil? and rest[0..3] == "NOTE"
290323
section= Note.new(tag)
291324
section.add_detail 1, "TEXT", rest[5..-1]
292325
section_type= "NOTE"
293326
else
327+
$stderr.puts "unknown "+
328+
"type:'#{type}' tag:#{tag}" \
329+
if not ["", "SUBM", "REPO"].include? type
294330
section= GedSection.new(tag)
295331
section_type= ""
296332
end
297333
end
298334
else
299-
#add a detail to the section
300-
if section_type == 'FAM' && ['HUSB', 'WIFE', 'CHIL'].include?(tag)
301-
section.add_relation(tag, find_by_individual_gid(rest)) if section
302-
else
303-
section.add_detail level, tag, rest if section
335+
if tag == "OBJE" and find_by_object_gid(rest).nil?
336+
object_section= Object.new(rest)
337+
object_level= level
338+
elsif not object_section.nil?
339+
if level <= object_level
340+
@objects.push object_section \
341+
if object_section.fields.length > 0
342+
object_section= nil
343+
else
344+
object_section.add_detail(
345+
level.to_i-object_level.to_i+1,
346+
tag, rest)
347+
end
348+
next if not object_level.nil?
304349
end
305350

306351
if tag == "PLAC" and find_by_place(rest).nil?
307352
place_section= Place.new(rest)
308353
@places.push place_section
309354
place_level= level
310355
place_level_higher= false
311-
end
312-
313-
if place_section
356+
elsif not place_section.nil?
314357
if level < place_level
315358
place_section= nil
316-
place_level= nil
317-
place_level_higher= false
318359
elsif level == place_level
319360
place_level_higher= false
320361
if "OBJE".include? tag
321362
place_level_higher= true
322-
place_section.add_detail((level.to_i-place_level.to_i+1), tag, rest)
363+
place_section.add_detail(
364+
level.to_i-place_level.to_i+1,
365+
tag, rest)
323366
end
324367
elsif place_level_higher
325-
place_section.add_detail((level.to_i-place_level.to_i+1), tag, rest)
368+
place_section.add_detail(
369+
level.to_i-place_level.to_i+1,
370+
tag, rest)
326371
end
372+
next if not place_level.nil?
373+
end
374+
375+
#add a detail to the section
376+
if section_type == 'FAM' && ['HUSB', 'WIFE', 'CHIL'].include?(tag)
377+
section.add_relation(tag, find_by_individual_gid(rest)) if section
378+
else
379+
section.add_detail level, tag, rest if section
327380
end
381+
328382
end
329383
end
330384

@@ -333,13 +387,16 @@ def refresh
333387
when "INDI" then @individuals.push section if section
334388
when "FAM" then @families.push section if section
335389
when "NOTE" then @notes.push section if section
390+
when "OBJE" then @objects.push section if section
391+
when "SOUR" then @sources.push section if section
336392
else
337393
@sections.push section if section
338394
end
339395

340396
@individuals.compact!
341397
@families.compact!
342398
@notes.compact!
399+
@objects.compact!
343400
@sections.compact!
344401
@places.compact!
345402
@sources.compact!
@@ -370,6 +427,13 @@ def find_by_node_gid(gid)
370427
return nil
371428
end
372429

430+
def find_by_object_gid(gid)
431+
@objects.each do |n|
432+
return n if n.gid == gid
433+
end
434+
return nil
435+
end
436+
373437
def find_by_place(name)
374438
@places.each do |p|
375439
return p if p.name == name

0 commit comments

Comments
 (0)