Class: BrowserOfBabel::Page

Inherits:
Holotheca show all
Defined in:
lib/browser_of_babel/page.rb

Overview

Bottom-level holotheca in the library. Identifier is between 1 and 410. Contains 3200 characters:

- lowercase latin letters,
- digits,
- spaces,
- commas and periods.

Constant Summary

Constants inherited from Holotheca

Holotheca::DEFAULT_URL_FORMATTER

Instance Attribute Summary

Attributes included from Holotheca::Holarchy::ClassMethods

#child_class, #parent_class

Attributes included from Holotheca::Holarchy

#identifier, #parent

Instance Method Summary collapse

Methods inherited from Holotheca

holotheca_name, identifier_class, identifier_format, #initialize, #to_s, #to_s_part, #to_url, #to_url_part, url_format

Methods included from Holotheca::Holarchy::ClassMethods

#>>, #depth, #holarchy, #root

Methods included from Holotheca::Holarchy

#depth, #dig, #down, #initialize, #path, #path_identifiers, #root, #up

Constructor Details

This class inherits a constructor from BrowserOfBabel::Holotheca

Instance Method Details

#pageObject #pageObject #pageObject

Note:

This performs a network request to fetch the page’s content.

Get text from the page. Character indices are 1-based.

Overloads:

  • #pageObject

    Parameters:

    • start (Integer)
    • length (Integer)
  • #pageObject

    Parameters:

    • range (Range<Integer>)
  • #pageObject

    Parameters:

    • index (Integer)

See Also:

  • String#[]


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/browser_of_babel/page.rb', line 51

def [](start_or_range, length = nil)
  range =
    if start_or_range.is_a?(Range)
      (start_or_range.begin - 1)..(start_or_range.end - 1)
    elsif length
      (start_or_range - 1)..(start_or_range + length - 1)
    else
      (start_or_range - 1)..(start_or_range - 1)
    end
  text.[](range)
end

#textString

Note:

This performs a network request to fetch the page’s content.

Get the page’s contents as a blob of text.

Returns:

  • (String)


36
37
38
# File 'lib/browser_of_babel/page.rb', line 36

def text
  content.text
end

#titleString

Note:

This performs a network request to fetch the page’s content.

Get the page’s title (volume’s title + page number).

Returns:

  • (String)


29
30
31
# File 'lib/browser_of_babel/page.rb', line 29

def title
  content.title
end

#volume_titleString

Note:

This performs a network request to fetch the page’s content.

Get the volume’s title.

Returns:

  • (String)


21
22
23
24
# File 'lib/browser_of_babel/page.rb', line 21

def volume_title
  # @type var _ : String
  _ = title[/.+(?= \d+\z)/]
end