abbreviato 0.9.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c45a839708f9051531a8821f6714cad6d2d81aa0
4
- data.tar.gz: 5154f12f2c978e5f82a5b54aed8633f45a6a6464
3
+ metadata.gz: 5085c8300a7d9a509c4f72e2cb9daf5a3e1d4b87
4
+ data.tar.gz: eef2da69fa0c5ce8be05f46c6ccdc62e3942ed3f
5
5
  SHA512:
6
- metadata.gz: 75ec15f2a424ad7363bd1867cb8d91a3e746293af8e7465a0540bb0ef66f40ce0e2bd639525018005701591cd26981f0e6f0d96b44fe7f0fea36a76e375a7f3f
7
- data.tar.gz: f22ac6c084c2ee56b490ee98552157c4f751a44264250a21630d560b08802d6e4980a093473c8b67a7f50a0dac289274fa0ca7d2601294ea5f4d56472ecd39da
6
+ metadata.gz: 9a3d5bdf9ddcd1804697a8904e86189016603f6d4cb9b982989279ec8388c794097fe03baff381c4643bd5388d444fc579e012fd4d87600e298c3e9986d66d9d
7
+ data.tar.gz: 381c985b43bab367387842aca67c1125fa57d89c02ff11d4b5e537d8865e96fa444fe44176765d224e098f221db9962a972f217454ace9ed0e0a2d6cd5e03ea5
data/README.md CHANGED
@@ -37,6 +37,13 @@ Abbreviato was designed with performance in mind. Its main motivation was that e
37
37
  bundle exec rake
38
38
  ```
39
39
 
40
+ ## Running a single test
41
+
42
+ ```ruby
43
+ rspec spec/abbreviato/abbreviato_spec.rb
44
+ rspec spec/abbreviato/abbreviato_spec.rb:357
45
+ ```
46
+
40
47
  ## Running all checks
41
48
 
42
49
  ```ruby
@@ -12,6 +12,9 @@ module Abbreviato
12
12
  # @param [String] source the XML source to truncate
13
13
  # @param [Hash] user_options truncation options
14
14
  # @option user_options [Integer] :max_length Maximum length
15
+ # @option user_options [Boolean] :truncate_incomplete_row Indicates whether or
16
+ # not to truncate the last row in a table if truncation due to max_length
17
+ # occurs in the middle of a row.
15
18
  # @option user_options [String] :tail Text to append when the truncation happens
16
19
  # @option user_options [Boolean] :fragment Indicates whether the document to be truncated is an HTML fragment
17
20
  # or an entire document (with `HTML`, `HEAD` & `BODY` tags). Setting to true prevents automatic addition of
@@ -22,6 +25,18 @@ module Abbreviato
22
25
  truncated_sax_document = TruncatedSaxDocument.new(DEFAULT_OPTIONS.merge(user_options))
23
26
  parser = Nokogiri::HTML::SAX::Parser.new(truncated_sax_document)
24
27
  parser.parse(source) { |context| context.replace_entities = false }
28
+
29
+ if truncated_sax_document.truncated && user_options[:truncate_incomplete_row]
30
+ html_fragment = Nokogiri::HTML.fragment(truncated_sax_document.truncated_string.strip)
31
+ last_table_in_doc = html_fragment.xpath('.//table').last
32
+ cols_in_first_row = last_table_in_doc.xpath('.//tr').first.xpath('.//td').length
33
+ last_table_in_doc.xpath('.//tr').reverse.each do |element|
34
+ element.remove if element.xpath('.//td').length != cols_in_first_row
35
+ end
36
+
37
+ return [html_fragment.to_html, truncated_sax_document.truncated]
38
+ end
39
+
25
40
  [truncated_sax_document.truncated_string.strip, truncated_sax_document.truncated]
26
41
  end
27
42
  end
@@ -1,3 +1,3 @@
1
1
  module Abbreviato
2
- VERSION = '0.9.4'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abbreviato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Manrubia