@@ -209,6 +209,20 @@ def get_cached_detail(sym, tag); raise "NOT AVAILABLE FOR NOTES"; end
209
209
def fields ; raise "NOT AVAILABLE FOR NOTES" ; end
210
210
end
211
211
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
+
212
226
class Place < GedSection
213
227
attr_reader :name
214
228
@@ -221,8 +235,18 @@ def initialize(gid)
221
235
def objs ; return get_details ( "OBJE" ) ; end
222
236
end
223
237
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
+
224
248
class Gedcom
225
- attr_reader :individuals , :families , :tags , :sections , :places , :sources
249
+ attr_reader :individuals , :families , :notes , :objects , : sections, :places , :sources , :tags
226
250
227
251
def initialize ( file_name )
228
252
@file_name = file_name
@@ -233,9 +257,10 @@ def refresh
233
257
@individuals = [ ]
234
258
@families = [ ]
235
259
@notes = [ ]
260
+ @objects = [ ]
236
261
@sections = [ ]
237
262
@places = [ ]
238
- @sources = [ ] #TODO
263
+ @sources = [ ]
239
264
@tags = [ ]
240
265
241
266
f = File . new ( @file_name , 'r' )
@@ -251,31 +276,31 @@ def refresh
251
276
section_type = ""
252
277
section = nil
253
278
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
257
281
258
282
f . each do |gedline |
259
-
260
283
level , tag , rest = gedline . chop . split ( ' ' , 3 )
261
284
262
285
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
266
288
267
289
# push the last section
268
290
case section_type
269
291
when "" then 1
270
292
when "INDI" then @individuals . push section if section
271
293
when "FAM" then @families . push section if section
272
294
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
273
297
else
274
298
@sections . push section if section
275
299
end
276
300
277
301
#start a new section
278
- case rest . to_s . chomp
302
+ type = rest . to_s . chomp
303
+ case type
279
304
when "INDI"
280
305
#create an individual
281
306
section = Individual . new ( tag )
@@ -284,47 +309,76 @@ def refresh
284
309
#create a family
285
310
section = Family . new ( tag )
286
311
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'
287
320
else
288
321
#create a general section
289
322
if not rest . nil? and rest [ 0 ..3 ] == "NOTE"
290
323
section = Note . new ( tag )
291
324
section . add_detail 1 , "TEXT" , rest [ 5 ..-1 ]
292
325
section_type = "NOTE"
293
326
else
327
+ $stderr. puts "unknown " +
328
+ "type:'#{ type } ' tag:#{ tag } " \
329
+ if not [ "" , "SUBM" , "REPO" ] . include? type
294
330
section = GedSection . new ( tag )
295
331
section_type = ""
296
332
end
297
333
end
298
334
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?
304
349
end
305
350
306
351
if tag == "PLAC" and find_by_place ( rest ) . nil?
307
352
place_section = Place . new ( rest )
308
353
@places . push place_section
309
354
place_level = level
310
355
place_level_higher = false
311
- end
312
-
313
- if place_section
356
+ elsif not place_section . nil?
314
357
if level < place_level
315
358
place_section = nil
316
- place_level = nil
317
- place_level_higher = false
318
359
elsif level == place_level
319
360
place_level_higher = false
320
361
if "OBJE" . include? tag
321
362
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 )
323
366
end
324
367
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 )
326
371
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
327
380
end
381
+
328
382
end
329
383
end
330
384
@@ -333,13 +387,16 @@ def refresh
333
387
when "INDI" then @individuals . push section if section
334
388
when "FAM" then @families . push section if section
335
389
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
336
392
else
337
393
@sections . push section if section
338
394
end
339
395
340
396
@individuals . compact!
341
397
@families . compact!
342
398
@notes . compact!
399
+ @objects . compact!
343
400
@sections . compact!
344
401
@places . compact!
345
402
@sources . compact!
@@ -370,6 +427,13 @@ def find_by_node_gid(gid)
370
427
return nil
371
428
end
372
429
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
+
373
437
def find_by_place ( name )
374
438
@places . each do |p |
375
439
return p if p . name == name
0 commit comments