Class: OoxmlParser::Size
- Inherits:
-
Object
- Object
- OoxmlParser::Size
- Defined in:
- lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#orientation ⇒ Object
Returns the value of attribute orientation.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
- .get_name_by_size(height, width, is_portrait = true) ⇒ Object
-
.parse(node) ⇒ Size
Parse BordersProperties.
Instance Method Summary collapse
-
#==(other) ⇒ Object
noinspection RubyUnnecessaryReturnStatement.
-
#initialize(height = nil, width = nil, orientation = :portrait) ⇒ Size
constructor
A new instance of Size.
-
#name ⇒ String
Get human format name.
-
#same_dimensions?(other) ⇒ True, False
Compare dimensions of size, ignoring orientation.
- #to_s ⇒ Object
Constructor Details
#initialize(height = nil, width = nil, orientation = :portrait) ⇒ Size
Returns a new instance of Size.
5 6 7 8 9 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 5 def initialize(height = nil, width = nil, orientation = :portrait) @height = height @width = width @orientation = orientation end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 3 def height @height end |
#orientation ⇒ Object
Returns the value of attribute orientation.
3 4 5 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 3 def orientation @orientation end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 3 def width @width end |
Class Method Details
.get_name_by_size(height, width, is_portrait = true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 11 def self.get_name_by_size(height, width, is_portrait = true) unless is_portrait swap_value = height height = width width = swap_value end return 'US Letter' if height == '15840' && width == '12240' return 'US Legal' if height == '20160' && width == '12240' return 'A4' if height == '16838' && width == '11906' return 'A5' if height == '11900' && width == '8396' return 'B5' if height == '14179' && width == '9978' return 'Envelope #10' if height == '13680' && width == '5941' return 'Envelope DL' if height == '12478' && width == '6242' return 'Tabloid' if height == '24474' && width == '15840' return 'A3' if height == '23817' && width == '16838' return 'Tabloid Oversize' if height == '25914' && width == '17280' return 'ROC 16K' if height == '15477' && width == '11157' return 'Envelope Choukei 3' if height == '13317' && width == '6797' return 'Super B/A3' if height == '27354' && width == '18720' 'Unknown page size: Height ' + height.to_s + ' Width ' + width.to_s end |
.parse(node) ⇒ Size
Parse BordersProperties
75 76 77 78 79 80 81 82 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 75 def self.parse(node) size = Size.new size.orientation = node.attribute('orient').value.to_sym unless node.attribute('orient').nil? # TODO: implement and understand, why 566.929, but not `unit_delimeter` size.height = (node.attribute('h').value.to_f / 566.929).round(2) size.width = (node.attribute('w').value.to_f / 566.929).round(2) size end |
Instance Method Details
#==(other) ⇒ Object
noinspection RubyUnnecessaryReturnStatement
38 39 40 41 42 43 44 45 46 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 38 def ==(other) is_same = false if (@height == other.height) && (@width == other.width) && (@orientation == other.orientation) is_same = true end is_same end |
#name ⇒ String
Returns get human format name.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 55 def name return 'US Letter' if same_dimensions?(Size.new(27.94, 21.59)) return 'US Legal' if same_dimensions?(Size.new(35.56, 21.59)) return 'A4' if same_dimensions?(Size.new(29.7, 21.0)) return 'A5' if same_dimensions?(Size.new(20.99, 14.81)) return 'B5' if same_dimensions?(Size.new(25.01, 17.6)) return 'Envelope #10' if same_dimensions?(Size.new(24.13, 10.48)) return 'Envelope DL' if same_dimensions?(Size.new(22.01, 11.01)) return 'Tabloid' if same_dimensions?(Size.new(43.17, 27.94)) return 'A3' if same_dimensions?(Size.new(42.01, 29.7)) return 'Tabloid Oversize' if same_dimensions?(Size.new(45.71, 30.48)) return 'ROC 16K' if same_dimensions?(Size.new(27.3, 19.68)) return 'Envelope Choukei 3' if same_dimensions?(Size.new(23.49, 11.99)) return 'Super B/A3' if same_dimensions?(Size.new(48.25, 33.02)) "Unknown page size: Height #{@height} Width #{@width}" end |
#same_dimensions?(other) ⇒ True, False
Returns compare dimensions of size, ignoring orientation.
49 50 51 52 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 49 def same_dimensions?(other) (@height == other.height) && (@width == other.width) || (@height == other.width) && (@width == other.height) end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/size.rb', line 33 def to_s 'Height: ' + @height.to_s + ' Width: ' + @width.to_s + ' Orientation: ' + @orientation.to_s end |