Class: Layout::Pages

Inherits:
Object
  • Object
show all
Includes:
Enumerable

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 Method Summary # collapse

Instance Method Details

#[](index) ⇒ Layout::Page

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

Examples:

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

Parameters:

  • index (Integer)

    The index of the Layout::Page to return.

Returns:

Raises:

  • (IndexError)

    if index is out of range

Version:

  • LayOut 2018

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

The #add method adds a new Layout::Page to the Document. The newly added Layout::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

Returns The newly added Layout::Page.

Parameters:

  • name (String) (defaults to: nil)

    The name for the new page.

Returns:

Version:

  • LayOut 2018

#each {|page| ... } ⇒ Object

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 Layout::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 Layout::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:

Returns:

  • (Integer, nil)

Version:

  • LayOut 2018

#initialLayout::Page

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

Examples:

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

Returns:

Version:

  • LayOut 2018

#initial=(page) ⇒ Object #initial=(index) ⇒ Object

The #initial= method sets the initial Layout::Page that will be displayed the next time the Document is opened. This value will change whenever the Layout::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) ⇒ Object

    Parameters:

    Raises:

    • (ArgumentError)

      if page does not belong to the Document

  • #initial=(index) ⇒ Object

    Parameters:

    • index (Integer)

      The index of the Layout::Page to set as the initial one

    Raises:

    • (IndexError)

      if index is out of range

Version:

  • LayOut 2018

#lengthInteger Also known as: size

The #length method returns the number of Layout::Pages.

Examples:

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

Returns:

  • (Integer)

Version:

  • LayOut 2018

#remove(page) ⇒ Object #remove(index) ⇒ Object

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

Examples:

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

Overloads:

Version:

  • LayOut 2018

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

The #reorder method moves a Layout::Page to a different index within the Document's list of pages. This will move the Layout::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) ⇒ Object

    Parameters:

    Raises:

    • (ArgumentError)

      if the Layout::Page is not in the Document

    • (IndexError)

      if new_index is out of range

  • #reorder(index, new_index) ⇒ Object

    Parameters:

    • index (Integer)

      The index of the Layout::Page to be reordered

    • new_index (Integer)

      The index to put the Layout::Page at

    Raises:

    • (IndexError)

      if index or new_index is out of range

Version:

  • LayOut 2018