123456789_123456789_123456789_123456789_123456789_

Class: Layout::Pages

Relationships
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Enumerable
Inherits: Object

Overview

The Pages class is a container class for all pages in a Document.

Examples:

# Grab a handle to an existing LayOut document's pages.
doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages

# From here, we can add pages to or remove them from the document
pages.add("New Page")
pages.remove(pages[0])

Version:

  • LayOut 2018

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#initialLayout::Page (rw)

The #initial method returns the initial Page that will be displayed the next time the Document is opened. This value will change whenever the Page is changed in the Document in LayOut.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
page = pages.initial

Version:

  • LayOut 2018

#initial=(page) (rw) #initial=(index)

The #initial= method sets the initial Page that will be displayed the next time the Document is opened. This value will change whenever the Page is changed in the Document in LayOut.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
pages.initial = doc.pages[0]

Overloads:

  • #initial=(page)

    Parameters:

    Raises:

    • (ArgumentError)

      if page does not belong to the Document

  • #initial=(index)

    Parameters:

    • index (Integer)

      The index of the Page to set as the initial one

    Raises:

    • (IndexError)

      if index is out of range

Version:

  • LayOut 2018

Instance Method Details

#[](index) ⇒ Layout::Page

The #[] method returns a value from the array of Pages.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
page = pages[2]

Parameters:

  • index (Integer)

    The index of the Page to return.

Raises:

  • (IndexError)

    if index is out of range

Version:

  • LayOut 2018

#add(name = nil) ⇒ Layout::Page

The #add method adds a new Page to the Document. The newly added Page will be the last one in the Document.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
new_page = pages.add

Parameters:

  • name (String) (defaults to: nil)

    The name for the new page.

Returns:

Version:

  • LayOut 2018

#each {|page| ... }

Note:

Don’t remove content from this collection while iterating over it with #each. This would change the size of the collection and cause elements to be skipped as the indices change. Instead copy the current collection to an array using to_a and then use each on the array, when removing content.

The #each method iterates through all of the Pages.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
pages.each { |page|
  puts page.name
}

Yield Parameters:

Version:

  • LayOut 2018

#index(page) ⇒ Integer?

The #index method returns the index of the Page, or nil if it doesn’t exist in the Document.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
page_index = pages.index(pages.first) # Returns 0

Parameters:

Version:

  • LayOut 2018

#lengthInteger Also known as: #size

The #length method returns the number of Pages.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
num_pages = pages.length

Version:

  • LayOut 2018

#remove(page) #remove(index)

The #remove method deletes the given Page from the Document.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
pages.remove(pages[0])

Overloads:

  • #remove(page)

    Parameters:

    Raises:

    • (ArgumentError)

      if the Page is not in the Document

    • (ArgumentError)

      if the Page is the only one in the Document

  • #remove(index)

    Parameters:

    • index (Integer)

      The index of the Page to be removed

    Raises:

    • (ArgumentError)

      if the Page is the only one in the Document

    • (IndexError)

      if index is out of range

Version:

  • LayOut 2018

#reorder(page, new_index) #reorder(index, new_index)

The #reorder method moves a Page to a different index within the Document‘s list of pages. This will move the Page such that its new index becomes new_index.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
pages.reorder(pages[1], 3)

Overloads:

  • #reorder(page, new_index)

    Parameters:

    • page (Layout::Page)

      The Page to be reordered

    • new_index (Integer)

      The index to put the Page at

    Raises:

    • (ArgumentError)

      if the Page is not in the Document

    • (IndexError)

      if new_index is out of range

  • #reorder(index, new_index)

    Parameters:

    • index (Integer)

      The index of the Page to be reordered

    • new_index (Integer)

      The index to put the Page at

    Raises:

    • (IndexError)

      if index or new_index is out of range

Version:

  • LayOut 2018

#size

Alias for #length.