Module: Burly

Defined in:
lib/burly.rb,
lib/burly/parser.rb,
lib/burly/exceptions.rb,
lib/burly/parsers/html_parser.rb,
lib/burly/parsers/json_parser.rb,
lib/burly/parsers/plaintext_parser.rb

Defined Under Namespace

Modules: Parsers Classes: Parser, UnsupportedMimeType

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.registered_parsersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/burly.rb', line 16

def registered_parsers
  @registered_parsers
end

Class Method Details

.parse(document, mime_type: "text/plain", **options) ⇒ Array<String>

Parse a document for URLs.

Examples:

Parse a plaintext document.

Burly.parse(File.read("example.txt"))

Parse an HTML document

Burly.parse(File.read("example.html", mime_type: "text/html"))

Parse a JSON document.

Burly.parse(File.read("example.json"), mime_type: "application/json")

Parameters:

  • document (String, #to_s)

    The document to parse for URLs.

Returns:

  • (Array<String>)

Raises:



36
37
38
39
40
41
42
# File 'lib/burly.rb', line 36

def self.parse(document, mime_type: "text/plain", **options)
  parser = registered_parsers[mime_type]

  raise UnsupportedMimeType unless parser

  parser.new(document, **options).parse
end

.register_parser(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/burly.rb', line 45

def self.register_parser(klass)
  klass.mime_types.each { |mime_type| @registered_parsers[mime_type] = klass }
end