ooxml_parser 0.25.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 409ce77d24b38512604d5215a2bd6a54f887685db71cd9942c81935ef678f3b0
4
- data.tar.gz: 4f7edddf4bab2d5d6ab9485754b333a2943d2df96fdcc933d671e820cd9dc70d
3
+ metadata.gz: 8d10481491c8a8bb901c8514f5a7c19ee3b6482e8fb943f39b9191dbd057d395
4
+ data.tar.gz: efbdbe106e2e88c584e428b8536cedb96972033434b5e1457f6ae2b31946cdd4
5
5
  SHA512:
6
- metadata.gz: aad06b0a4dd775d5efe4411d43b87ebda68fe05a5a15924fb6773d77169141284baaf8047eee042634a2e6145649ac0fce2e9aa143d401587434598eeff5f73d
7
- data.tar.gz: c2ab404a2ab3f559a312da5953da7a668b4ae1c359ff790bc4b4d577ccbd453e4314844125cc64e144c884f9e187389586c98f085c4d27ca5837d8a1b9e61f9d
6
+ metadata.gz: b553b7f055d43a6a355592ac8c2d28b085795b0faadf12531f119d4a1d15b1c7bcd45a5a661aad611799aa3286266469b88c12792bb4c3bba0b6c3fac2a0f54d
7
+ data.tar.gz: 1a68d32efafe9ee2921ffd6c75a794dd340a4b6d814e4aa7daa6348fb1246644a12b99a071df7e7e1bfe84de02f15c96a4068f6227008ec051a1932b0bdb01db
@@ -4,6 +4,16 @@ module OoxmlParser
4
4
  # Docx Wrap Drawing
5
5
  class DocxWrapDrawing < OOXMLDocumentObject
6
6
  attr_accessor :wrap_text, :distance_from_text
7
+ # @return [Boolean] Specifies whether this floating DrawingML
8
+ # object is displayed behind the text of the
9
+ # document when the document is displayed.
10
+ # When a DrawingML object is displayed
11
+ # within a WordprocessingML document,
12
+ # that object can intersect with text in the
13
+ # document. This attribute shall determine
14
+ # whether the text or the object is rendered on
15
+ # top in case of overlapping.
16
+ attr_reader :behind_doc
7
17
 
8
18
  def initialize(parent: nil)
9
19
  @wrap_text = :none
@@ -14,10 +24,16 @@ module OoxmlParser
14
24
  # @param node [Nokogiri::XML:Element] node to parse
15
25
  # @return [DocxWrapDrawing] result of parsing
16
26
  def parse(node)
17
- unless node.attribute('behindDoc').nil?
18
- @wrap_text = :behind if node.attribute('behindDoc').value == '1'
19
- @wrap_text = :infront if node.attribute('behindDoc').value == '0'
27
+ node.attributes.each do |key, value|
28
+ case key
29
+ when 'behindDoc'
30
+ @behind_doc = attribute_enabled?(value)
31
+ end
20
32
  end
33
+
34
+ @wrap_text = :behind if @behind_doc == true
35
+ @wrap_text = :infront if @behind_doc == false
36
+
21
37
  node.xpath('*').each do |node_child|
22
38
  case node_child.name
23
39
  when 'wrapSquare'
@@ -60,8 +60,10 @@ module OoxmlParser
60
60
  to_s
61
61
  end
62
62
 
63
- # @return [String] color in hex value
63
+ # @return [String, nil] color in hex value or `nil` if color is not defined
64
64
  def to_hex
65
+ return nil if none?
66
+
65
67
  (@red.to_s(16).rjust(2, '0') + @green.to_s(16).rjust(2, '0') + @blue.to_s(16).rjust(2, '0')).upcase
66
68
  end
67
69
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # noinspection RubyTooManyInstanceVariablesInspection
4
3
  require_relative 'docx_paragraph_run/docx_paragraph_run_helpers'
5
4
  require_relative 'docx_paragraph_run/instruction_text'
6
5
  require_relative 'docx_paragraph_run/object'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # noinspection RubyTooManyInstanceVariablesInspection
4
3
  require_relative 'docx_paragraph/bookmark_start'
5
4
  require_relative 'docx_paragraph/bookmark_end'
6
5
  require_relative 'docx_paragraph/comment_range_end'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # noinspection RubyInstanceMethodNamingConvention
4
3
  require_relative 'document_structure/comments'
5
4
  require_relative 'document_structure/comments_extended'
6
5
  require_relative 'document_structure/docx_paragraph'
@@ -4,6 +4,6 @@ module OoxmlParser
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
6
  # [String] Version of Gem
7
- STRING = '0.25.0'
7
+ STRING = '0.26.0'
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  module OoxmlParser
4
4
  # Properties of XLSX column
5
5
  class XlsxColumnProperties < OOXMLDocumentObject
6
- attr_accessor :from, :to, :width, :style
6
+ attr_accessor :style
7
7
  # @return [True, False] is width custom
8
8
  attr_accessor :custom_width
9
9
  # @return [True, False] Flag indicating if the
@@ -12,6 +12,14 @@ module OoxmlParser
12
12
  # @return [True, False] Flag indicating if the
13
13
  # specified column(s) is hidden
14
14
  attr_reader :hidden
15
+ # @return [Integer] First column affected by this 'column info' record.
16
+ attr_reader :min
17
+ # @return [Integer] Last column affected by this 'column info' record.
18
+ attr_reader :max
19
+ # @return [Float] width in pixel, as stored in xml structure
20
+ attr_reader :width_raw
21
+ # @return [Float] width, in readable format
22
+ attr_reader :width
15
23
 
16
24
  # Parse XlsxColumnProperties object
17
25
  # @param node [Nokogiri::XML:Element] node to parse
@@ -20,13 +28,14 @@ module OoxmlParser
20
28
  node.attributes.each do |key, value|
21
29
  case key
22
30
  when 'min'
23
- @from = value.value.to_i
31
+ @min = value.value.to_i
24
32
  when 'max'
25
- @to = value.value.to_i
33
+ @max = value.value.to_i
26
34
  when 'style'
27
35
  @style = root_object.style_sheet.cell_xfs.xf_array[value.value.to_i]
28
36
  when 'width'
29
- @width = value.value.to_f - 0.7109375
37
+ @width_raw = value.value.to_f
38
+ @width = calculate_width(@width_raw)
30
39
  when 'customWidth'
31
40
  @custom_width = option_enabled?(node, 'customWidth')
32
41
  when 'bestFit'
@@ -38,6 +47,13 @@ module OoxmlParser
38
47
  self
39
48
  end
40
49
 
50
+ alias from min
51
+ alias to max
52
+
53
+ extend Gem::Deprecate
54
+ deprecate :from, 'min', 2099, 1
55
+ deprecate :to, 'max', 2099, 1
56
+
41
57
  # Parse list of XlsxColumnProperties
42
58
  # @param columns_width_node [Nokogiri::XML:Element] node to parse
43
59
  # @param parent [OOXMLDocumentObject] parent of result objects
@@ -50,5 +66,17 @@ module OoxmlParser
50
66
  end
51
67
  columns
52
68
  end
69
+
70
+ private
71
+
72
+ # TODO: Currently width calculation use some magick number from old time ago
73
+ # Actual formula is way more complicated and require data about
74
+ # font max width for single character.
75
+ # Read more in ECMA-376, §18.3.1.13
76
+ # @param [Float] value raw value for width
77
+ # @return [Float] width value
78
+ def calculate_width(value)
79
+ value - 0.7109375
80
+ end
53
81
  end
54
82
  end
@@ -12,6 +12,8 @@ module OoxmlParser
12
12
  attr_reader :style_index
13
13
  # @return [String] value of cell
14
14
  attr_reader :value
15
+ # @return [String] An A-1 style reference to a cell.
16
+ attr_reader :reference
15
17
  # @return [String] type of string
16
18
  attr_reader :type
17
19
 
@@ -31,6 +33,8 @@ module OoxmlParser
31
33
  @style_index = value.value.to_i
32
34
  when 't'
33
35
  @type = value.value.to_s
36
+ when 'r'
37
+ @reference = value.value.to_s
34
38
  end
35
39
  end
36
40
  node.xpath('*').each do |node_child|
@@ -60,6 +64,11 @@ module OoxmlParser
60
64
  @raw_text
61
65
  end
62
66
 
67
+ # @return [Coordinates] coordinates of cell
68
+ def coordinates
69
+ @coordinates ||= Coordinates.new.parse_string(@reference)
70
+ end
71
+
63
72
  private
64
73
 
65
74
  # @return [Nothing] parse text data
@@ -4,13 +4,17 @@ require_relative 'xlsx_row/xlsx_cell'
4
4
  module OoxmlParser
5
5
  # Single Row of XLSX
6
6
  class XlsxRow < OOXMLDocumentObject
7
- attr_accessor :cells, :height, :style, :hidden
7
+ attr_accessor :height, :style, :hidden
8
8
  # @return [True, False] true if the row height has been manually set.
9
9
  attr_accessor :custom_height
10
- # @return [Integer] Indicates to which row in the sheet this <row> definition corresponds.
10
+ # @return [Integer] Indicates to which row in the sheet
11
+ # this <row> definition corresponds.
11
12
  attr_accessor :index
13
+ # @return [Array<Cells>] cells of row, as in xml structure
14
+ attr_reader :cells_raw
12
15
 
13
16
  def initialize(parent: nil)
17
+ @cells_raw = []
14
18
  @cells = []
15
19
  super
16
20
  end
@@ -34,10 +38,22 @@ module OoxmlParser
34
38
  node.xpath('*').each do |node_child|
35
39
  case node_child.name
36
40
  when 'c'
37
- @cells[Coordinates.new.parse_string(node_child.attribute('r').value.to_s).column_number.to_i - 1] = XlsxCell.new(parent: self).parse(node_child)
41
+ @cells_raw << XlsxCell.new(parent: self).parse(node_child)
38
42
  end
39
43
  end
40
44
  self
41
45
  end
46
+
47
+ # @return [Array<XlsxCell, nil>] list of cell in row, with nil,
48
+ # if cell data is not stored in xml
49
+ def cells
50
+ return @cells if @cells.any?
51
+
52
+ cells_raw.each do |cell|
53
+ @cells[cell.coordinates.column_number.to_i - 1] = cell
54
+ end
55
+
56
+ @cells
57
+ end
42
58
  end
43
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxml_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-07-28 00:00:00.000000000 Z
13
+ date: 2022-08-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -605,7 +605,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
605
605
  - !ruby/object:Gem::Version
606
606
  version: '0'
607
607
  requirements: []
608
- rubygems_version: 3.3.19
608
+ rubygems_version: 3.3.20
609
609
  signing_key:
610
610
  specification_version: 4
611
611
  summary: OoxmlParser Gem