Class: Qiflib::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/qiflib_date.rb

Overview

Instances of this class represent a date from within a qif file, such as ‘D5/24/94’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string_value = '') ⇒ Date

Returns a new instance of Date.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/qiflib_date.rb', line 11

def initialize(string_value='')
  @cc, @yy, @mm, @dd = '00', '00', '00', '00'
  @string_value = "#{string_value}".tr('D','')
  tokens = @string_value.split('/')
  if (tokens && tokens.size > 2)
    m   = tokens[0].to_i
    d   = tokens[1].to_i
    y   = tokens[2].to_i
    @yy = tokens[2]
    y < 50 ? @cc = "20" : @cc = "19"
    m < 10 ? @mm = "0#{m}" : @mm = "#{m}"
    d < 10 ? @dd = "0#{d}" : @dd = "#{d}"
  end
  @ccyymmdd = "#{@cc}#{@yy}-#{@mm}-#{@dd}"
  @year     = "#{@cc}#{@yy}"
  @year_mm  = "#{@cc}#{@yy}-#{@mm}"
end

Instance Attribute Details

#ccyymmddObject

Returns the value of attribute ccyymmdd.



9
10
11
# File 'lib/qiflib_date.rb', line 9

def ccyymmdd
  @ccyymmdd
end

#ddObject

Returns the value of attribute dd.



9
10
11
# File 'lib/qiflib_date.rb', line 9

def dd
  @dd
end

#mmObject

Returns the value of attribute mm.



9
10
11
# File 'lib/qiflib_date.rb', line 9

def mm
  @mm
end

#string_valueObject

Returns the value of attribute string_value.



9
10
11
# File 'lib/qiflib_date.rb', line 9

def string_value
  @string_value
end

#yearObject

Returns the value of attribute year.



9
10
11
# File 'lib/qiflib_date.rb', line 9

def year
  @year
end

#year_mmObject

Returns the value of attribute year_mm.



9
10
11
# File 'lib/qiflib_date.rb', line 9

def year_mm
  @year_mm
end

#yyObject

Returns the value of attribute yy.



9
10
11
# File 'lib/qiflib_date.rb', line 9

def yy
  @yy
end

Instance Method Details

#to_sObject



29
30
31
# File 'lib/qiflib_date.rb', line 29

def to_s
  @ccyymmdd
end