Class: OoxmlParser::PageSize
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::PageSize
- Defined in:
- lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_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.
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 ⇒ Object
Methods inherited from OOXMLDocumentObject
#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(height = nil, width = nil, orientation = :portrait) ⇒ PageSize
Returns a new instance of PageSize.
5 6 7 8 9 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_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/page_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/page_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/page_size.rb', line 3 def width @width end |
Instance Method Details
#name ⇒ String
Returns get human format name.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb', line 22 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
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb', line 42 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.
16 17 18 19 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb', line 16 def same_dimensions?(other) (@height == other.height) && (@width == other.width) || (@height == other.width) && (@width == other.height) end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb', line 11 def to_s 'Height: ' + @height.to_s + ' Width: ' + @width.to_s + ' Orientation: ' + @orientation.to_s end |