Class: GEDCOM::DatePart
- Inherits:
-
GEDCOM_DATE_PARSER::GEDDate
- Object
- GEDCOM_DATE_PARSER::GEDDate
- GEDCOM::DatePart
- 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
Instance Method Summary collapse
- #<=>(dp) ⇒ Object
- #calendar ⇒ Object
- #compliance ⇒ Object
- #day ⇒ Object
- #epoch ⇒ Object
- #has_day? ⇒ Boolean
- #has_month? ⇒ Boolean
- #has_year? ⇒ Boolean
- #has_year_span? ⇒ Boolean
-
#initialize(type = GEDCOM_DATE_PARSER::GCTGREGORIAN, flags = NONE, data = nil) ⇒ DatePart
constructor
A new instance of DatePart.
- #month ⇒ Object
- #phrase ⇒ Object
- #to_s ⇒ Object
- #to_year ⇒ Object
- #year ⇒ Object
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 |
#calendar ⇒ Object
39 40 41 |
# File 'lib/gedcom_ruby/date.rb', line 39 def calendar @type end |
#compliance ⇒ Object
43 44 45 |
# File 'lib/gedcom_ruby/date.rb', line 43 def compliance @flags end |
#day ⇒ Object
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 |
#epoch ⇒ Object
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
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
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
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
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 |
#month ⇒ Object
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 |
#phrase ⇒ Object
47 48 49 50 |
# File 'lib/gedcom_ruby/date.rb', line 47 def phrase raise DateFormatException if( @flags != PHRASE ) @data end |
#to_s ⇒ Object
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_year ⇒ Object
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 |
#year ⇒ Object
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 |