Class: OoxmlParser::PageSize
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::PageSize
- Defined in:
- lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb
Overview
Class for data of PageSize
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.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#initialize(height = nil, width = nil, orientation = :portrait) ⇒ PageSize
constructor
A new instance of PageSize.
-
#name ⇒ String
Get human format name.
-
#parse(node) ⇒ PageSize
Parse PageSize.
-
#same_dimensions?(other) ⇒ True, False
Compare dimensions of size, ignoring orientation.
-
#to_s ⇒ String
Convert to string.
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(height = nil, width = nil, orientation = :portrait) ⇒ PageSize
Returns a new instance of PageSize.
8 9 10 11 12 13 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 8 def initialize(height = nil, width = nil, orientation = :portrait) @height = height @width = width @orientation = orientation super(parent: nil) end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 6 def height @height end |
#orientation ⇒ Object
Returns the value of attribute orientation.
6 7 8 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 6 def orientation @orientation end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 6 def width @width end |
Instance Method Details
#name ⇒ String
Returns get human format name.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 27 def name return 'US Letter' if same_dimensions?(PageSize.new(OoxmlSize.new(27.94, :centimeter), OoxmlSize.new(21.59, :centimeter))) return 'US Legal' if same_dimensions?(PageSize.new(OoxmlSize.new(35.56, :centimeter), OoxmlSize.new(21.59, :centimeter))) return 'A4' if same_dimensions?(PageSize.new(OoxmlSize.new(29.7, :centimeter), OoxmlSize.new(21.0, :centimeter))) return 'A5' if same_dimensions?(PageSize.new(OoxmlSize.new(20.99, :centimeter), OoxmlSize.new(14.81, :centimeter))) return 'B5' if same_dimensions?(PageSize.new(OoxmlSize.new(25.01, :centimeter), OoxmlSize.new(17.6, :centimeter))) return 'Envelope #10' if same_dimensions?(PageSize.new(OoxmlSize.new(24.13, :centimeter), OoxmlSize.new(10.48, :centimeter))) return 'Envelope DL' if same_dimensions?(PageSize.new(OoxmlSize.new(22.01, :centimeter), OoxmlSize.new(11.01, :centimeter))) return 'Tabloid' if same_dimensions?(PageSize.new(OoxmlSize.new(43.17, :centimeter), OoxmlSize.new(27.94, :centimeter))) return 'A3' if same_dimensions?(PageSize.new(OoxmlSize.new(42.01, :centimeter), OoxmlSize.new(29.7, :centimeter))) return 'Tabloid Oversize' if same_dimensions?(PageSize.new(OoxmlSize.new(45.71, :centimeter), OoxmlSize.new(30.48, :centimeter))) return 'ROC 16K' if same_dimensions?(PageSize.new(OoxmlSize.new(27.3, :centimeter), OoxmlSize.new(19.68, :centimeter))) return 'Envelope Choukei 3' if same_dimensions?(PageSize.new(OoxmlSize.new(23.49, :centimeter), OoxmlSize.new(11.99, :centimeter))) return 'Super B/A3' if same_dimensions?(PageSize.new(OoxmlSize.new(48.25, :centimeter), OoxmlSize.new(33.02, :centimeter))) "Unknown page size: Height #{@height} Width #{@width}" end |
#parse(node) ⇒ PageSize
Parse PageSize
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 48 def parse(node) node.attributes.each do |key, value| case key when 'orient' @orientation = value.value.to_sym when 'h' @height = OoxmlSize.new(value.value.to_f) when 'w' @width = OoxmlSize.new(value.value.to_f) end end self end |
#same_dimensions?(other) ⇒ True, False
Returns compare dimensions of size, ignoring orientation.
21 22 23 24 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 21 def same_dimensions?(other) ((@height == other.height) && (@width == other.width)) || ((@height == other.width) && (@width == other.height)) end |
#to_s ⇒ String
Returns convert to string.
16 17 18 |
# File 'lib/ooxml_parser/docx_parser/document_structure/page_properties/page_size.rb', line 16 def to_s "Height: #{@height} Width: #{@width} Orientation: #{@orientation}" end |