Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ short_name = full_name.downcase
# Many of these tasks came from the ruby-hl7 project rakefile
#

desc 'Default: Run RSpec Tests'
desc 'Default: Run RSpec Tests'
task :default => :spec

# Gem Specification
spec = Gem::Specification.new do |s|
spec = Gem::Specification.new do |s|
s.name = short_name
s.version = GEDCOM::VERSION
s.author = "Phillip Davies"
Expand All @@ -30,7 +30,7 @@ spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.summary = "Ruby GEDCOM Parser Library"
s.rubyforge_project = short_name
s.description = "A simple library to enable easy, callback-based parsing of GEDCOM data files"
s.description = "A simple library to enable easy, callback-based parsing of GEDCOM data files"
s.files = FileList["{lib,ext,samples,tests}/**/*"].to_a
s.require_path = "lib"
s.autorequire = short_name
Expand All @@ -42,8 +42,8 @@ spec = Gem::Specification.new do |s|
end

# Gem Task
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar = true
Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar = true
end

# RSpec Test Task
Expand All @@ -61,25 +61,25 @@ namespace :spec do
t.libs << $:
t.rcov = true
end

desc 'Heckle the Date tests'
Spec::Rake::SpecTask.new('heckle_dates') do |t|
t.warning = true
t.spec_files = FileList['tests/date_spec.rb']
t.libs << $:
t.spec_opts << " --heckle GEDCOM::Date"
end

desc 'Heckle the DatePart test'
Spec::Rake::SpecTask.new('heckle_dateparts') do |t|
t.warning = true
t.spec_files = FileList['tests/datepart_spec.rb']
t.libs << $:
t.spec_opts << " --heckle GEDCOM::DatePart"
end

end


# Clean up Task
desc 'Clean up all the extras'
Expand Down Expand Up @@ -119,7 +119,7 @@ task :release => [:clean, :package] do |t|
rf.add_release spec.rubyforge_project, spec.name, spec.version.to_s, *files
end

# Task to install the gem locally
# Task to install the gem locally
desc 'Install the package as a gem'
task :install_gem => [:clean, :package] do
sh "sudo gem install pkg/*.gem"
Expand Down
30 changes: 15 additions & 15 deletions ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static

RUBY_EXTCONF_H =
CFLAGS = -fPIC -O2 -fno-strict-aliasing -pipe -fPIC
RUBY_EXTCONF_H =
CFLAGS = -fPIC -O2 -fno-strict-aliasing -pipe -fPIC
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
CPPFLAGS =
CXXFLAGS = $(CFLAGS)
DLDFLAGS = -L. -rdynamic -Wl,-soname,$(.TARGET)
CPPFLAGS =
CXXFLAGS = $(CFLAGS)
DLDFLAGS = -L. -rdynamic -Wl,-soname,$(.TARGET)
LDSHARED = cc -shared
AR = ar
EXEEXT =
EXEEXT =

RUBY_INSTALL_NAME = ruby18
RUBY_SO_NAME = ruby18
Expand All @@ -66,26 +66,26 @@ COPY = cp

#### End of system configuration section. ####

preload =
preload =

libpath = . $(libdir)
LIBPATH = -L'.' -L'$(libdir)' -Wl,-R'$(libdir)'
DEFFILE =
DEFFILE =

CLEANFILES = mkmf.log
DISTCLEANFILES =
DISTCLEANFILES =

extout =
extout_prefix =
target_prefix =
LOCAL_LIBS =
extout =
extout_prefix =
target_prefix =
LOCAL_LIBS =
LIBS = $(LIBRUBYARG_SHARED) -lcrypt -lm -rpath=/usr/lib:/usr/local/lib -pthread -lc
SRCS = gedcom.c gedcom_date.c
OBJS = gedcom.o gedcom_date.o
TARGET = _gedcom
DLLIB = $(TARGET).so
EXTSTATIC =
STATIC_LIB =
EXTSTATIC =
STATIC_LIB =

RUBYCOMMONDIR = $(sitedir)$(target_prefix)
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
Expand Down
10 changes: 5 additions & 5 deletions lib/gedcom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Expand All @@ -26,7 +26,7 @@ module GEDCOM

# Possibly a better way to do this?
VERSION = "0.2.1"

class Parser
def initialize &block
@before = {}
Expand Down Expand Up @@ -71,7 +71,7 @@ def context


protected

def check_proc_or_block proc, &block
unless proc or block_given?
raise ArgumentError.new("proc or block required")
Expand Down Expand Up @@ -125,7 +125,7 @@ def unwind_to level
end

def concat_data tag, rest
if @dataStack[-1].nil?
if @dataStack[-1].nil?
@dataStack[-1] = rest
else
if @ctxStack[-1] == 'BLOB'
Expand Down
74 changes: 37 additions & 37 deletions lib/gedcom_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
module GEDCOM

class DatePart < GEDCOM_DATE_PARSER::GEDDate

# Flags
NONE = GEDCOM_DATE_PARSER::GFNONE
PHRASE = GEDCOM_DATE_PARSER::GFPHRASE
Expand All @@ -31,102 +31,102 @@ class DatePart < GEDCOM_DATE_PARSER::GEDDate
NOMONTH = GEDCOM_DATE_PARSER::GFNOMONTH
NOYEAR = GEDCOM_DATE_PARSER::GFNOYEAR
YEARSPAN = GEDCOM_DATE_PARSER::GFYEARSPAN

def initialize(type=GEDCOM_DATE_PARSER::GCTGREGORIAN, flags=NONE, data=nil)
super( type, flags, data )
end

def calendar
@type
end

def compliance
@flags
end

def phrase
raise DateFormatException if( @flags != PHRASE )
@data
end

def has_day?
return false if ( @flags == PHRASE )
return ((@data.flags & NODAY) != 0 ? false : true)
end

def has_month?
return false if ( @flags == PHRASE )
return ((@data.flags & NOMONTH) != 0 ? false : true)
end

def has_year?
return false if ( @flags == PHRASE )
return ((@data.flags & NOYEAR) != 0 ? false : true)
end

def has_year_span?
return false if ( @flags == PHRASE )
return ((@data.flags & YEARSPAN) != 0 ? true : false)
end

def day
raise DateFormatException, "date has no day" if (@flags == PHRASE || (@data.flags & NODAY) != 0)
@data.day
end

def month
raise DateFormatException, "date has no month" if (@flags == PHRASE || (@data.flags & NOMONTH) != 0)
@data.month
end

def year
raise DateFormatException, "date has no year" if (@flags == PHRASE || (@data.flags & NOYEAR) != 0)
@data.year
end

def to_year
raise DateFormatException, "date has no year span" if (@flags == PHRASE || (@data.flags & YEARSPAN) == 0)
@data.year2
end

def epoch
raise DateFormatException, "only gregorian dates have epoch" if ( @flags == PHRASE || @type != GEDCOM_DATE_PARSER::GCTGREGORIAN )
return (( @data.adbc == GEDCOM_DATE_PARSER::GEDADBCBC ) ? "BC" : "AD" )
end

def to_s
GEDCOM_DATE_PARSER::DateParser.build_gedcom_date_part_string( self )
end

def <=>( dp )
return -1 if has_year? and !dp.has_year?
return 1 if !has_year? and dp.has_year?

if has_year? and dp.has_year?
rc = ( year <=> dp.year )
return rc unless rc == 0
end

return -1 if dp.has_month? and !dp.has_month?
return 1 if !dp.has_month? and dp.has_month?

if has_month? and dp.has_month?
rc = ( month <=> dp.month )
return rc unless rc == 0
end

return -1 if dp.has_day? and !dp.has_day?
return 1 if !dp.has_day? and dp.has_day?

if has_day? and dp.has_day?
rc = ( day <=> dp.day )
return rc unless rc == 0
end

return 0
end
end #/ DatePart

class Date < GEDCOM_DATE_PARSER::GEDDateValue
# Calendar types
NONE = GEDCOM_DATE_PARSER::GCNONE
Expand Down Expand Up @@ -173,62 +173,62 @@ def initialize ( date_str, calendar=DateType::DEFAULT )
end
err_msg += "'"
if (block_given?)
yield( err_msg )
yield( err_msg )
else
raise DateFormatException, err_msg
end
end
end

def format
@flags
end

def first
@date1
end

def last
@date2
end

def to_s
GEDCOM_DATE_PARSER::DateParser.build_gedcom_date_string( self )
end

def is_date?
(@flags & (NONE | ABOUT | CALCULATED | ESTIMATED | BEFORE | AFTER | BETWEEN \
| FROM | TO | FROMTO | INTERPRETED)) != 0 ? false : true
end

def is_range?
(@flags & (BETWEEN | FROMTO)) != 0 ? true : false
end

def <=>( d )
if is_date? and d.is_date?
rc = ( first <=> d.first )
return rc unless rc == 0

if is_range? and d.is_range?
return ( last <=> d.last )
elsif is_range?
return 1
elsif d.is_range?
return -1
end

return 0
elsif is_date?
return -1
elsif d.is_date?
return 1
end

return format <=> d.format
end
end

class DateType
GREGORIAN = GEDCOM_DATE_PARSER::GCTGREGORIAN
JULIAN = GEDCOM_DATE_PARSER::GCTJULIAN
Expand All @@ -238,8 +238,8 @@ class DateType
UNKNOWN = GEDCOM_DATE_PARSER::GCTUNKNOWN
DEFAULT = GEDCOM_DATE_PARSER::GCTDEFAULT
end

class DateFormatException < Exception

end
end
Loading