Module: MdnQuery

Defined in:
lib/mdn_query.rb,
lib/mdn_query/list.rb,
lib/mdn_query/entry.rb,
lib/mdn_query/table.rb,
lib/mdn_query/errors.rb,
lib/mdn_query/search.rb,
lib/mdn_query/section.rb,
lib/mdn_query/version.rb,
lib/mdn_query/document.rb,
lib/mdn_query/traverse_dom.rb,
lib/mdn_query/search_result.rb

Overview

Query the Mozilla Developer Network documentation.

Defined Under Namespace

Classes: Document, Entry, Error, HttpRequestFailed, List, NoEntryFound, Search, SearchResult, Section, Table, TraverseDom

Constant Summary collapse

BASE_URL =

The base url for the search queries.

'https://developer.mozilla.org/search'.freeze
VERSION =

The version of the gem

'0.2.3'.freeze

Class Method Summary collapse

Class Method Details

.first_match(query, options = {}) ⇒ MdnQuery::Document

Searches the given query and returns the first fetched entry in the list.

Parameters:

  • query (String)

    the query to search for

  • options (Hash) (defaults to: {})

    additional query options (see MdnQuery::Search#initialize)

Returns:

Raises:



48
49
50
51
# File 'lib/mdn_query.rb', line 48

def self.first_match(query, options = {})
  entry = list(query, options).first
  entry.content
end

.list(query, options = {}) ⇒ MdnQuery::List

Searches the given query and creates a list with the results.

Parameters:

  • query (String)

    the query to search for

  • options (Hash) (defaults to: {})

    additional query options (see MdnQuery::Search#initialize)

Returns:

Raises:



31
32
33
34
35
36
37
38
# File 'lib/mdn_query.rb', line 31

def self.list(query, options = {})
  search = MdnQuery::Search.new(query, options)
  list = search.execute.to_list
  if list.empty?
    raise MdnQuery::NoEntryFound.new(query, options), 'No entry found'
  end
  list
end

.open_first_match(query, options = {}) ⇒ void

This method returns an undefined value.

Searches the given query and opens the first entry in the default browser.

Parameters:

  • query (String)

    the query to search for

  • options (Hash) (defaults to: {})

    additional query options (see MdnQuery::Search#initialize)

Raises:



74
75
76
77
# File 'lib/mdn_query.rb', line 74

def self.open_first_match(query, options = {})
  entry = list(query, options).first
  entry.open
end

.open_list(query, options = {}) ⇒ void

This method returns an undefined value.

Searches the given query and opens the result in the default browser.

Parameters:

  • query (String)

    the query to search for

  • options (Hash) (defaults to: {})

    additional query options (see MdnQuery::Search#initialize)

Raises:



61
62
63
64
# File 'lib/mdn_query.rb', line 61

def self.open_list(query, options = {})
  search = MdnQuery::Search.new(query, options)
  search.open
end