Class: KingDta::Dta

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/king_dta/dta.rb

Direct Known Subclasses

Dtaus, Dtazv

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#convert_text

Constructor Details

#initialize(date = Date.today) ⇒ Dta

Create a new dta string.

Parameter #

typ<Date>

date when the the transfer is to be created

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
# File 'lib/king_dta/dta.rb', line 10

def initialize(date=Date.today )
  raise ArgumentError.new("Wrong date format. Make it a Time or Date object with yyyy-mm-dd") unless date.respond_to?(:strftime)
  @date         = date
  @value_pos    = true  #values are positive by default changed by first booking
  @closed       = false
  @default_text = ''
end

Instance Attribute Details

#default_textObject

Returns the value of attribute default_text.



5
6
7
# File 'lib/king_dta/dta.rb', line 5

def default_text
  @default_text
end

Instance Method Details

#account=(account) ⇒ Object

Set the sending account(you own)

Parameter

account<Account>

the sending account, must be an instance of class

KingDta::Account

Raises:



21
22
23
24
# File 'lib/king_dta/dta.rb', line 21

def account=(  )
  raise Exception.new("Come on, i need an Account object") unless .kind_of?( Account )
  @account = 
end

#add(booking) ⇒ Object

Add a booking. The prefix (pos/neg) is beeing checked if it is identical with the last one

Parameter

booking<Booking>

KingDta::Booking object

Raises

error if the prefix within the bookings has changed

Raises:



45
46
47
48
49
50
51
# File 'lib/king_dta/dta.rb', line 45

def add ( booking )
  raise Exception.new("The file has alreay been closed, cannot add new booking") if @closed
  #the first booking decides wether all values are po or negative
  @value_pos = booking.pos?  if bookings.empty?
  raise Exception.new("The prefix within bookings changed from #{@value_pos} to #{booking.pos?}") if @value_pos != booking.pos?
  bookings << booking
end

#bookingsObject

Array of bookings



31
32
33
# File 'lib/king_dta/dta.rb', line 31

def bookings
  @bookings ||= []
end

#create_file(filename = 'dta.txt') ⇒ Object

Create a DTA-File, from current dta information

Parameter

filename<String>

defaults to dta.txt



56
57
58
59
60
# File 'lib/king_dta/dta.rb', line 56

def create_file(filename ='dta.txt')
  file = open( filename, 'w')
  file  << create
  file.close()
end

#dta_stringObject

The dtaus format as string. All data is appended to it during creation



27
28
29
# File 'lib/king_dta/dta.rb', line 27

def dta_string
  @dta_string ||= ''
end