Class: MdnQuery::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/mdn_query/document.rb

Overview

A document of an entry of the Mozilla Developer Network documentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, url = nil) ⇒ MdnQuery::Document

Creates a new document with an initial top level section.

Parameters:

  • title (String)

    the titel of the top level section

  • url (String) (defaults to: nil)

    the URL to the document on the web



15
16
17
18
19
# File 'lib/mdn_query/document.rb', line 15

def initialize(title, url = nil)
  @title = title
  @url = url
  @section = MdnQuery::Section.new(title)
end

Instance Attribute Details

#sectionMdnQuery::Section (readonly)

Returns the top level section.

Returns:



8
9
10
# File 'lib/mdn_query/document.rb', line 8

def section
  @section
end

#titleString (readonly)

Returns:

  • (String)


5
6
7
# File 'lib/mdn_query/document.rb', line 5

def title
  @title
end

#urlString (readonly)

Returns:

  • (String)


5
6
7
# File 'lib/mdn_query/document.rb', line 5

def url
  @url
end

Instance Method Details

#openvoid

This method returns an undefined value.

Opens the document in the default web browser if a URL has been specified.



24
25
26
# File 'lib/mdn_query/document.rb', line 24

def open
  Launchy.open(@url) unless @url.nil?
end

#to_sString Also known as: to_md

Returns the string representation of the document.

Returns:

  • (String)


31
32
33
# File 'lib/mdn_query/document.rb', line 31

def to_s
  @section.to_s
end