Class: SunatBooks::Ple::Base

Inherits:
Object
  • Object
show all
Includes:
CommonUtils, Utils
Defined in:
lib/sunat_books/ple/base.rb

Direct Known Subclasses

Buys, Sales

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#book_code, #check_layout, #get_file, #get_value, #path, #ple_book_name

Methods included from CommonUtils

#available_value?

Constructor Details

#initialize(ruc, tickets, month, year, options = {}) ⇒ Base

ruc => company’s ruc in string format tickets => an array of objects that respond to a layout’s methods month => a number that represent a month year => a number that represent a year options =>

:yml  => to define a custom layout file
:layout => to define a custom name for a specific layout method
:book_format => to define ple book format to use


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sunat_books/ple/base.rb', line 24

def initialize(ruc, tickets, month, year, options = {})
  @book_format = options[:book_format]
  yml_path = options[:yml] || default_yml(book_format)
  raise SunatBooks::Errors::InvalidLayoutError unless File.exist?(yml_path)

  fields = YAML.load_file(yml_path)
  check_layout(options, fields)
  content = !tickets.empty? ? 1 : 0

  name = ple_book_name(book_format, ruc, month, year, nil, content)
  filename = "#{path}#{name}.txt"
  get_file(tickets, fields, filename)
end

Instance Attribute Details

#book_formatObject (readonly)

Returns the value of attribute book_format.



14
15
16
# File 'lib/sunat_books/ple/base.rb', line 14

def book_format
  @book_format
end

#fileObject

Returns the value of attribute file.



13
14
15
# File 'lib/sunat_books/ple/base.rb', line 13

def file
  @file
end