Module: DocXify

Defined in:
lib/docxify/element/table.rb,
lib/docxify.rb,
lib/docxify/version.rb,
lib/docxify/document.rb,
lib/docxify/template.rb,
lib/docxify/container.rb,
lib/docxify/element/base.rb,
lib/docxify/element/file.rb,
lib/docxify/element/image.rb,
lib/docxify/element/divider.rb,
lib/docxify/element/paragraph.rb,
lib/docxify/element/page_break.rb,
lib/docxify/element/table_cell.rb,
lib/docxify/element/page_layout.rb,
lib/docxify/element/web_address.rb

Overview

Word PageLayouts are a weird concept; instead of a wrapping element or a “this applies to content from here on down”, it’s applied retrospectively to the content that came before it.

Defined Under Namespace

Modules: Element, Template Classes: Container, Document, Error

Constant Summary collapse

UNITS_PER_CM =
(1440 / 2.54)
A4_PORTRAIT_WIDTH =

cm2dxa(21)

11_906
A4_PORTRAIT_HEIGHT =

cm2dxa(29.7)

15_840
A4_LANDSCAPE_WIDTH =
A4_PORTRAIT_HEIGHT
A4_LANDSCAPE_HEIGHT =
A4_PORTRAIT_WIDTH
VERSION =
"0.1.7".freeze

Class Method Summary collapse

Class Method Details

.cm2dxa(value) ⇒ Object

Used for most sizes

Raises:

  • (ArgumentError)


27
28
29
30
31
32
# File 'lib/docxify.rb', line 27

def self.cm2dxa(value)
  value = value.to_f
  raise ArgumentError.new("Value must be greater than or equal to 0") if value.negative?

  (value * UNITS_PER_CM).to_i
end

.cm2emu(value) ⇒ Object

Used for image sizes

Raises:

  • (ArgumentError)


59
60
61
62
63
64
# File 'lib/docxify.rb', line 59

def self.cm2emu(value)
  value = value.to_f
  raise ArgumentError.new("Value must be greater than or equal to 0") if value.negative?

  (value * 360_000).to_i
end

.dxa2cm(value) ⇒ Object

Inverse of cm2dxa

Raises:

  • (ArgumentError)


35
36
37
38
39
40
# File 'lib/docxify.rb', line 35

def self.dxa2cm(value)
  value = value.to_f
  raise ArgumentError.new("Value must be greater than or equal to 0") if value.negative?

  (value / UNITS_PER_CM).to_i
end

.pt2halfpt(value) ⇒ Object

Used for font sizes

Raises:

  • (ArgumentError)


43
44
45
46
47
48
# File 'lib/docxify.rb', line 43

def self.pt2halfpt(value)
  value = value.to_f
  raise ArgumentError.new("Value must be greater than or equal to 0") if value.negative?

  (value * 2).to_i
end

.pt2spacing(value) ⇒ Object

Used for spacing

Raises:

  • (ArgumentError)


51
52
53
54
55
56
# File 'lib/docxify.rb', line 51

def self.pt2spacing(value)
  value = value.to_f
  raise ArgumentError.new("Value must be greater than or equal to 0") if value.negative?

  (value * 20).to_i
end