Class: Boxcars::URLText

Inherits:
Boxcar
  • Object
show all
Defined in:
lib/boxcars/boxcar/url_text.rb

Overview

A Boxcar that reads text from a URL.

Constant Summary collapse

DESC =

the description of this boxcar

"useful when you want to get text from a URL."

Instance Attribute Summary

Attributes inherited from Boxcar

#description, #name, #parameters, #return_direct

Instance Method Summary collapse

Methods inherited from Boxcar

#apply, assi, #call, #conduct, hist, #input_keys, #load, #output_keys, #save, #schema, syst, user, #validate_inputs, #validate_outputs

Constructor Details

#initialize(name: "FetchURL", description: DESC) ⇒ URLText

implements a boxcar that uses the Google SerpAPI to get answers to questions.

Parameters:

  • name (String) (defaults to: "FetchURL")

    The name of the boxcar. Defaults to classname.

  • description (String) (defaults to: DESC)

    A description of the boxcar. Defaults to SERPDESC.



12
13
14
# File 'lib/boxcars/boxcar/url_text.rb', line 12

def initialize(name: "FetchURL", description: DESC)
  super
end

Instance Method Details

#run(url) ⇒ String

Get text from a url.

Parameters:

  • url (String)

    The url

Returns:

  • (String)

    The text for the url.



19
20
21
22
# File 'lib/boxcars/boxcar/url_text.rb', line 19

def run(url)
  url = URI.parse(url)
  do_encoding(get_answer(url))
end