{"id":13739655,"url":"https://github.com/pdavies011010/gedcom-ruby","last_synced_at":"2025-05-08T19:34:37.526Z","repository":{"id":438988,"uuid":"60825","full_name":"pdavies011010/gedcom-ruby","owner":"pdavies011010","description":"A Ruby library for easily doing custom, callback-based GEDCOM parsing","archived":false,"fork":false,"pushed_at":"2008-12-05T19:20:59.000Z","size":622,"stargazers_count":17,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T19:07:31.427Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pdavies011010.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2008-10-08T14:30:12.000Z","updated_at":"2019-08-13T13:37:29.000Z","dependencies_parsed_at":"2022-07-07T23:30:34.057Z","dependency_job_id":null,"html_url":"https://github.com/pdavies011010/gedcom-ruby","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdavies011010%2Fgedcom-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdavies011010%2Fgedcom-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdavies011010%2Fgedcom-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdavies011010%2Fgedcom-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pdavies011010","download_url":"https://codeload.github.com/pdavies011010/gedcom-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253135528,"owners_count":21859662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T04:00:36.234Z","updated_at":"2025-05-08T19:34:37.175Z","avatar_url":"https://github.com/pdavies011010.png","language":"Ruby","funding_links":[],"categories":["Parsers"],"sub_categories":["Ruby"],"readme":"#PCD -- Using \"AD\" as the epoch isn't allowed... is this correct behavior? If BC isn't\r\n# supplied, AD is assumed, but it seems to me it should at least be allowed grammar\r\n\r\nGEDCOM-Ruby\r\n-----------\r\n\r\nThis is a module for the Ruby language that defines a callback GEDCOM parser.\r\nIt does not do any validation of a GEDCOM file, but, using application-defined\r\ncallback hooks, can traverse any well-formed GEDCOM.\r\n\r\nThe module also includes a sophisticated date parser that can parse any\r\nstandard GEDCOM-formatted date (see the GEDCOM spec for details on the\r\nformat).\r\n\r\n\r\nInstallation\r\n------------\r\n\r\nTo install, you will need a Ruby interpreter. \r\n\r\nYou can try the samples by typing:\r\n\r\n  ruby samples/count.rb samples/royal.ged\r\n  ruby samples/birthdays.rb samples/royal.ged\r\n\r\n\r\nAlternately, a C extension version of the date parser can be built. In order to\r\nbuild you will need a C compiler (gcc is preferred).\r\n\r\n  cd lib/\r\n  ruby extconf.rb\r\n  make\r\n  make install\r\n\r\nAnd then uncomment the line in gedcom.rb \r\n   #require '_gedcom'\r\n\r\nand comment out\r\n   require 'gedcom_date'\r\n\r\nUsage\r\n-----\r\n\r\nTo use this module in your own programs, you can either inherit from the GEDCOM::Parser class\r\n(in which case the initialize method should call 'super' before doing anything else), or you\r\ncan instantiate the GEDCOM::Parser class directly.\r\n\r\nEither way, the setPreHandler and setPostHandler methods should then be used to register\r\ncallbacks for specified contexts.  A \"context\" is simply an array of strings, where each\r\nelement of the array specifies a GEDCOM row type.  For example:\r\n\r\n  [ \"INDI\" ] -\u003e this context defines a row on which an individual is introduced.\r\n  [ \"INDI\", \"BIRT\", \"DATE\" ] -\u003e this context defines the birthdate of an individual.\r\n\r\nCallbacks are registered as follows:\r\n\r\n  setPreHandler( context, function [, parm] )\r\n  setPostHandler( context, function [, parm] )\r\n\r\nThe 'context' is (as was described above) an array of strings, and the function is the Method\r\nobject to invoke.  The optional 'parm' method is a parameter that should be passed to the callback\r\nwhen it is invoked.  This can be used to allow the same callback to handle multiple different\r\ncontexts.\r\n\r\nThe 'pre' handler is called as soon as the context is recognized, before anything else is done.\r\nThe 'post' handler is called when the given context is about to expire.  For example, if the context\r\nwere [ \"INDI\" ], the pre handler would be called as soon as a row of type 'INDI' at level 0 was\r\nencountered, while the post handler would be called as soon as another row of level 0 was encountered,\r\nbefore that row's pre handler was invoked.  This allows you do perform initialization and commit\r\noperations.\r\n\r\nEach callback should take three parameters:\r\n\r\n  def callbackFunction( data, cookie, parm )\r\n    ...\r\n  end\r\n\r\nThe 'data' parameter is the text for the row's data (ie, the text that follows the row's type).\r\nThe 'cookie' parameter is the value that was passed to the parser's initialize method (if any),\r\nand 'parm' is the parameter that was specified when the callback was registered.\r\n\r\nTo parse a file, simply call the parser's 'parse' method, passing the name of the file to\r\nparse.\r\n\r\n\r\nAPI Reference\r\n-------------\r\n\r\n  module GEDCOM\r\n\r\n    class Parser\r\n\r\n      def initialize( cookie = nil )\r\n        :: Creates the parser, with the given 'cookie' (application defined value) which will\r\n           be passed to every callback.\r\n\r\n      def setPreHandler( context, func, parm = nil )\r\n        :: Registers the given function (Method object) to be called as soon as the given\r\n           context is recognized.  The given 'parm' value will be passed to the callback.\r\n\r\n      def setPostHandler( context, func, parm = nil )\r\n        :: Registers the given function (Method object) to be called as soon as the given\r\n           context expires.  The given 'parm' value will be passed to the callback.\r\n      \r\n      def parse( file )\r\n        :: Opens and parses the file with the given name, invoking callbacks as the registered\r\n           contexts are recognized.\r\n\r\n\r\n    class Date\r\n\r\n      def initialize( date_str, calendar=DateType::DEFAULT )\r\n      def initialize( date_str, calendar=DateType::DEFAULT ) { |err_msg| ... }\r\n        :: Creates a new GEDCOM Date object from the given string.  In the first form, if\r\n           the string does not define a valid date, a GEDCOM::DateFormatException is raised.\r\n           In the second form, an exception is not raised, but the given block is called\r\n           when there is an error.  Also, in the second form, a Date object is still returned,\r\n           but it will contain nothing except the string that was passed to it.\r\n\r\n      def Date.safe_new( date_str )\r\n        :: Creates a new GEDCOM Date object, but never throws a DateFormatException.\r\n\r\n      def format\r\n        :: Returns one of the following constants, indicating what the format of the date is:\r\n             NONE, ABOUT, CALCULATED, ESTIMATED, BEFORE, AFTER, BETWEEN, FROM, TO, FROMTO,\r\n             INTERPRETED, CHILD, CLEARED, COMPLETED, INFANT, PRE1970, QUALIFIED, STILLBORN,\r\n             SUBMITTED, UNCLEARED, BIC, DNS, DNSCAN, DEAD\r\n\r\n      def first\r\n        :: Returns a GEDCOM::DatePart object that defines the first part of the date.\r\n\r\n      def last\r\n        :: Returns a GEDCOM::DatePart object that defines the last part of the date.  This\r\n           will only be valid for a date format of BETWEEN or FROMTO (indicating a range\r\n           of dates).\r\n\r\n      def to_s\r\n        :: Returns the date formatted as a string.\r\n\r\n      def is_date?\r\n        :: Returns true if the Date object defines a date, but returns false if it\r\n           defines some non-date value (ie, there was an error parsing the date, or if the\r\n           date format is one of CHILD, CLEARED, COMPLETED, INFANT, PRE1970, QUALIFIED,\r\n           STILLBORN, SUBMITTED, UNCLEARED, BIC, DNS, DNSCAN, or DEAD).\r\n\r\n      def is_range?\r\n        :: Returns true if the Date object defines a date range (ie, format is either\r\n           BETWEEN or FROMTO).  If this is true, then Date.last will return the end of\r\n           the range.\r\n\r\n      def \u003c=\u003e( date )\r\n        :: Compares this date with the parameter, and returns -1, 0, or 1.\r\n\r\n\r\n    class DatePart\r\n\r\n      def calendar\r\n        :: Returns the calendar that was used to represent the given date.  Valid values\r\n           are DateType::GREGORIAN, DateType::JULIAN, DateType::HEBREW, DateType::FRENCH,\r\n           DateType::FUTURE, DateType::UNKNOWN, and DateType::DEFAULT.\r\n\r\n      def compliance\r\n        :: Returns the compliance of the date (ie, whether it is a valid date or not).\r\n           Valid values are DatePart::NONE (meaning it is a valid date), DatePart::PHRASE\r\n           (meaning the date contains a phrase, not a date) and DatePart::NONSTANDARD\r\n           (meaning there was an error parsing the date).\r\n\r\n      def phrase\r\n        :: If the compliance is DatePart::PHRASE, this will return the phrase value.\r\n           Otherwise, this will raise a DateFormatException.\r\n\r\n      def has_day?\r\n        :: Returns true if the date contains a day value.\r\n\r\n      def has_month?\r\n        :: Returns true if the date contains a month value.\r\n\r\n      def has_year?\r\n        :: Returns true if the date contains a year value.\r\n\r\n      def has_year_span?\r\n        :: Returns true if the date contains a span of years (valid only for\r\n           DateType::GREGORIAN calendars).  This means the date was formatted\r\n           like '25 Jul 1974-1980'.\r\n\r\n      def day\r\n        :: Returns the day portion of the date, if it has a day.  If it does not\r\n           have a day, a DateFormatException is raised.\r\n\r\n      def month\r\n        :: Returns the month portion of the date, if it has a month.  If it does not\r\n           have a month, a DateFormatException is raised.  (The month value will\r\n           be an integer, with 1 being the first month of the year.)\r\n\r\n      def year\r\n        :: Returns the year portion of the date, if it has a year.  If it does not\r\n           have a year, a DateFormatException is raised.\r\n\r\n      def to_year\r\n        :: Returns the second year portion of the date, if it has a year span.  If\r\n           it does not contain a year span, a DateFormatException is raised.\r\n      \r\n      def epoch\r\n        :: Returns either \"BC\" or \"AD\", as appropriate.\r\n\r\n      def to_s\r\n        :: Converts the DatePart object to a string.\r\n\r\n      def \u003c=\u003e( date_part )\r\n        :: Compares this date_part with the parameter, and returns -1, 0, or 1.\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdavies011010%2Fgedcom-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpdavies011010%2Fgedcom-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdavies011010%2Fgedcom-ruby/lists"}