Class: KingDta::Dta
Instance Attribute Summary collapse
-
#default_text ⇒ Object
Returns the value of attribute default_text.
Instance Method Summary collapse
-
#account=(account) ⇒ Object
- Set the sending account(you own) === Parameter account<Account>
-
the sending account, must be an instance of class KingDta::Account.
-
#add(booking) ⇒ Object
Add a booking.
-
#bookings ⇒ Object
Array of bookings.
-
#create_file(filename = 'dta.txt') ⇒ Object
- Create a DTA-File, from current dta information === Parameter filename<String>
-
defaults to dta.txt.
-
#dta_string ⇒ Object
The dtaus format as string.
-
#initialize(date = Date.today) ⇒ Dta
constructor
Create a new dta string.
Methods included from Helper
Constructor Details
#initialize(date = Date.today) ⇒ Dta
Create a new dta string.
Parameter #
- typ<Date>
-
date when the the transfer is to be created
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_text ⇒ Object
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
21 22 23 24 |
# File 'lib/king_dta/dta.rb', line 21 def account=( account ) raise Exception.new("Come on, i need an Account object") unless account.kind_of?( Account ) @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
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 |
#bookings ⇒ Object
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_string ⇒ Object
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 |