sunat_books 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +2 -5
  5. data/README.mkd +9 -3
  6. data/lib/sunat_books.rb +6 -6
  7. data/lib/sunat_books/common_utils.rb +9 -0
  8. data/lib/sunat_books/csv/base.rb +63 -0
  9. data/lib/sunat_books/csv/option_error.rb +8 -0
  10. data/lib/sunat_books/pdf/base.rb +134 -0
  11. data/lib/sunat_books/pdf/buys.rb +36 -0
  12. data/lib/sunat_books/pdf/count_sum.rb +24 -0
  13. data/lib/{books → sunat_books/pdf}/diary_entries.rb +1 -3
  14. data/lib/{books → sunat_books/pdf}/layouts/buys.yml +0 -0
  15. data/lib/{books → sunat_books/pdf}/layouts/sales.yml +0 -0
  16. data/lib/{books → sunat_books/pdf}/locale.rb +0 -0
  17. data/lib/{books → sunat_books/pdf}/locales/es.yml +0 -0
  18. data/lib/sunat_books/pdf/page.rb +48 -0
  19. data/lib/{books → sunat_books/pdf}/pages_utils.rb +1 -1
  20. data/lib/sunat_books/pdf/sales.rb +35 -0
  21. data/lib/sunat_books/pdf/simplified_diary.rb +94 -0
  22. data/lib/sunat_books/pdf/trading_book.rb +50 -0
  23. data/lib/{books → sunat_books/pdf}/utils.rb +4 -6
  24. data/lib/sunat_books/ple/base.rb +76 -0
  25. data/lib/sunat_books/ple/buys.rb +38 -0
  26. data/lib/{ple_books → sunat_books/ple}/layouts/buys.yml +0 -0
  27. data/lib/{ple_books → sunat_books/ple}/layouts/sales.yml +0 -0
  28. data/lib/sunat_books/ple/sales.rb +22 -0
  29. data/sunat_books.gemspec +2 -2
  30. data/test/{csv_books → csv}/base_test.rb +8 -5
  31. data/test/{books → pdf}/base_test.rb +0 -0
  32. data/test/pdf/buys_test.rb +27 -0
  33. data/test/{books → pdf}/page_test.rb +4 -4
  34. data/test/{books → pdf}/pages_utils_test.rb +32 -2
  35. data/test/pdf/sales_test.rb +15 -0
  36. data/test/{books → pdf}/utils_test.rb +7 -1
  37. data/test/{ple_books_test.rb → ple/base_test.rb} +2 -2
  38. data/test/{ple_books → ple}/buys_test.rb +8 -8
  39. metadata +38 -35
  40. data/Gemfile.lock +0 -83
  41. data/lib/books/base.rb +0 -132
  42. data/lib/books/buys.rb +0 -72
  43. data/lib/books/count_sum.rb +0 -22
  44. data/lib/books/page.rb +0 -44
  45. data/lib/books/sales.rb +0 -73
  46. data/lib/books/simplified_diary.rb +0 -97
  47. data/lib/csv_books/base.rb +0 -67
  48. data/lib/csv_books/option_error.rb +0 -6
  49. data/lib/ple_books/base.rb +0 -75
  50. data/lib/ple_books/buys.rb +0 -36
  51. data/lib/ple_books/sales.rb +0 -20
  52. data/test/books/buys_test.rb +0 -57
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
- module PleBooks
6
- class Buys < Base
7
- def initialize(ruc, tickets, month, year, options = {})
8
- # ruc => company's ruc in string format
9
- # tickets => an array of objects that respond to a layout's methods
10
- # month => a number that represent a month
11
- # year => a number that represent a year
12
- # options =>
13
- # :yml => to define a custom layout file
14
- # :layout => to define a custom name for a specific layout method
15
-
16
- book_name = self.class.name.downcase.sub("plebooks::", "")
17
- dir = File.dirname(__FILE__)
18
- yml_path = options[:yml] || "#{dir}/layouts/#{book_name}.yml"
19
- fields = YAML.load_file(yml_path)
20
- check_layout(options, fields)
21
- content = !tickets.empty? ? 1 : 0
22
- name = ple_book_name("8.1", ruc, month, year, nil, content)
23
-
24
- filename = "#{path}#{name}.txt"
25
- get_file(tickets, fields, filename)
26
- end
27
-
28
- def insert_layout_fields(options, fields)
29
- options[:layout].each do |key, value|
30
- i = fields.index(key.to_s)
31
- fields.delete(key.to_s)
32
- fields.insert(i, value)
33
- end
34
- end
35
- end
36
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "ple_books/base"
4
-
5
- module PleBooks
6
- class Sales < Base
7
- def initialize(ruc, tickets, month, year, options = {})
8
- book_name = self.class.name.downcase.sub("plebooks::", "")
9
- dir = File.dirname(__FILE__)
10
- yml_path = options[:yml] || "#{dir}/layouts/#{book_name}.yml"
11
- fields = YAML.load_file(yml_path)
12
- check_layout(options, fields)
13
- content = !tickets.empty? ? 1 : 0
14
-
15
- name = ple_book_name("14.2", ruc, month, year, nil, content)
16
- @filename = "#{path}#{name}.txt"
17
- get_file(tickets, fields, @filename)
18
- end
19
- end
20
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../helper"
4
- require_relative "../../lib/books/pages_utils"
5
-
6
- include PagesUtils
7
-
8
- setup do
9
- @company = Company.new(ruc: Faker::Number.number(11), name: Faker::Name.name)
10
- end
11
-
12
- test "render pdf, have a parseable pdf" do
13
- tickets = []
14
- view = Object.new.tap { |o| o.extend(Prawn::View) }
15
- pdf = Books::Buys.new(@company, tickets, view, 2, 3015)
16
- page_counter = PDF::Inspector::Page.analyze(pdf.render)
17
- assert pdf.page_count == 1
18
- assert page_counter.pages.size == 1
19
- end
20
-
21
- test "have correct text in header" do
22
- tickets = []
23
- view = Object.new.tap { |o| o.extend(Prawn::View) }
24
- pdf = Books::Buys.new(@company, tickets, view, 2, 3015)
25
- reader = PDF::Reader.new(StringIO.new(pdf.render))
26
- assert reader.pages.first.text.include?("REGISTRO DE COMPRAS")
27
- end
28
-
29
- test "#page_not_full return a page" do
30
- pages = []
31
- setup_pages(pages, 20, 5)
32
- first = pages.at(1)
33
- page = page_not_full(first, pages, 20)
34
- assert_equal page.class, Books::Page
35
- end
36
-
37
- test "#page_not_full return last page when length is less than page_max" do
38
- pages = []
39
- setup_pages(pages, 20, 5)
40
- first_page = pages.at(1)
41
- page = page_not_full(first_page, pages, 5)
42
- assert_equal page, first_page
43
- end
44
-
45
- test "#page_not_full return new page when last page is full" do
46
- pages = []
47
- setup_pages(pages, 20, 5)
48
- first_page = pages.at(1)
49
- first_page.length += 5
50
- current_page = pages.at(2)
51
- page = page_not_full(first_page, pages, 5)
52
- assert_equal page, current_page
53
- assert_equal page.page_number, 2
54
- end
55
-
56
- test "#row_data prepare data that will be include in table's rows" do
57
- end