Class: NFE::RPS
- Inherits:
-
Object
- Object
- NFE::RPS
- Defined in:
- lib/rps.rb
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#footer ⇒ Object
readonly
Returns the value of attribute footer.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #add_detail(fields) ⇒ Object
- #add_header(fields) ⇒ Object
-
#initialize ⇒ RPS
constructor
A new instance of RPS.
- #save_to_file(path = "./") ⇒ Object
- #set_footer ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ RPS
Returns a new instance of RPS.
5 6 7 8 9 |
# File 'lib/rps.rb', line 5 def initialize @header = Header.new = .new @details = Array.new end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
3 4 5 |
# File 'lib/rps.rb', line 3 def details @details end |
#footer ⇒ Object (readonly)
Returns the value of attribute footer.
3 4 5 |
# File 'lib/rps.rb', line 3 def end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
3 4 5 |
# File 'lib/rps.rb', line 3 def header @header end |
Instance Method Details
#add_detail(fields) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rps.rb', line 17 def add_detail fields detail = Detail.new detail << fields if detail.valid? @details << detail else raise Errors::InvalidDetailError, /Invalid Detail: #{detail.to_hash}/ end end |
#add_header(fields) ⇒ Object
11 12 13 14 15 |
# File 'lib/rps.rb', line 11 def add_header fields @header << fields raise Errors::InvalidHeaderError, /Invalid Header: #{@header.to_hash}/ if !@header.valid? return @header.fields end |
#save_to_file(path = "./") ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/rps.rb', line 56 def save_to_file path = "./" filename = "#{path}/RPS_#{@details.first.to_hash[:issuing_date]}.txt" file = File.new(filename, "w") saved = file.write(self.to_s) file.close return filename if saved end |
#set_footer ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rps.rb', line 27 def total_amount = 0 total_tax_amount = 0 @details.each do |detail| total_amount += detail.to_hash[:amount].to_i total_tax_amount += detail.to_hash[:tax_amount].to_i end << {total_detail_lines: @details.count.to_s, total_amount: total_amount.to_s, total_tax_amount: total_tax_amount.to_s} end |
#to_s ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rps.rb', line 42 def to_s if self.valid? string = @header.to_s @details.each do |detail| string += detail.to_s end string += .to_s return string else raise Errors::InvalidRPSError end end |
#valid? ⇒ Boolean
38 39 40 |
# File 'lib/rps.rb', line 38 def valid? return (@header.valid? and @details.count and .valid?) end |