Class: GEDCOM::DatePart

Inherits:
GEDCOM_DATE_PARSER::GEDDate show all
Defined in:
lib/gedcom_ruby/date.rb

Constant Summary collapse

NONE =

Flags

GEDCOM_DATE_PARSER::GFNONE
PHRASE =
GEDCOM_DATE_PARSER::GFPHRASE
NONSTANDARD =
GEDCOM_DATE_PARSER::GFNONSTANDARD
NOFLAG =
GEDCOM_DATE_PARSER::GFNOFLAG
NODAY =
GEDCOM_DATE_PARSER::GFNODAY
NOMONTH =
GEDCOM_DATE_PARSER::GFNOMONTH
NOYEAR =
GEDCOM_DATE_PARSER::GFNOYEAR
YEARSPAN =
GEDCOM_DATE_PARSER::GFYEARSPAN

Instance Attribute Summary

Attributes inherited from GEDCOM_DATE_PARSER::GEDDate

#data, #flags, #type

Instance Method Summary collapse

Constructor Details

#initialize(type = GEDCOM_DATE_PARSER::GCTGREGORIAN, flags = NONE, data = nil) ⇒ DatePart

Returns a new instance of DatePart.



35
36
37
# File 'lib/gedcom_ruby/date.rb', line 35

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

Instance Method Details

#<=>(dp) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/gedcom_ruby/date.rb', line 101

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

#calendarObject



39
40
41
# File 'lib/gedcom_ruby/date.rb', line 39

def calendar
  @type
end

#complianceObject



43
44
45
# File 'lib/gedcom_ruby/date.rb', line 43

def compliance
  @flags
end

#dayObject



72
73
74
75
# File 'lib/gedcom_ruby/date.rb', line 72

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

#epochObject



92
93
94
95
# File 'lib/gedcom_ruby/date.rb', line 92

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

#has_day?Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/gedcom_ruby/date.rb', line 52

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

#has_month?Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/gedcom_ruby/date.rb', line 57

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

#has_year?Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/gedcom_ruby/date.rb', line 62

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

#has_year_span?Boolean

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/gedcom_ruby/date.rb', line 67

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

#monthObject



77
78
79
80
# File 'lib/gedcom_ruby/date.rb', line 77

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

#phraseObject



47
48
49
50
# File 'lib/gedcom_ruby/date.rb', line 47

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

#to_sObject



97
98
99
# File 'lib/gedcom_ruby/date.rb', line 97

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

#to_yearObject



87
88
89
90
# File 'lib/gedcom_ruby/date.rb', line 87

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

#yearObject



82
83
84
85
# File 'lib/gedcom_ruby/date.rb', line 82

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