Class: NewsScraper::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/news_scraper/configuration.rb

Constant Summary collapse

DEFAULT_SCRAPE_PATTERNS_FILEPATH =
File.expand_path('../../../config/article_scrape_patterns.yml', __FILE__)
STOPWORDS_FILEPATH =
File.expand_path('../../../config/stopwords.yml', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

NewsScraper::Configuration.initialize initializes the scrape_patterns_filepath and the scrape_patterns_fetch_method to the DEFAULT_SCRAPE_PATTERNS_FILEPATH. It also sets stopwords to be used during extraction to a default set contained in STOPWORDS_FILEPATH

Set the scrape_patterns_filepath to nil to disable saving during training



13
14
15
16
17
# File 'lib/news_scraper/configuration.rb', line 13

def initialize
  self.scrape_patterns_filepath = DEFAULT_SCRAPE_PATTERNS_FILEPATH
  self.scrape_patterns_fetch_method = proc { default_scrape_patterns }
  self.stopwords_fetch_method = proc { YAML.load_file(STOPWORDS_FILEPATH) }
end

Instance Attribute Details

#scrape_patterns_fetch_methodObject

Returns the value of attribute scrape_patterns_fetch_method.



5
6
7
# File 'lib/news_scraper/configuration.rb', line 5

def scrape_patterns_fetch_method
  @scrape_patterns_fetch_method
end

#scrape_patterns_filepathObject

Returns the value of attribute scrape_patterns_filepath.



5
6
7
# File 'lib/news_scraper/configuration.rb', line 5

def scrape_patterns_filepath
  @scrape_patterns_filepath
end

#stopwords_fetch_methodObject

Returns the value of attribute stopwords_fetch_method.



5
6
7
# File 'lib/news_scraper/configuration.rb', line 5

def stopwords_fetch_method
  @stopwords_fetch_method
end

Instance Method Details

#scrape_patternsObject

NewsScraper::Configuration.scrape_patterns proxies scrape_patterns requests to scrape_patterns_fetch_method:

Returns

  • The result of calling the scrape_patterns_fetch_method proc, expected to be a hash



25
26
27
# File 'lib/news_scraper/configuration.rb', line 25

def scrape_patterns
  scrape_patterns_fetch_method.call
end

#stopwordsObject

NewsScraper::Configuration.stopwords proxies stopwords requests to stopwords_fetch_method:

Returns

  • The result of calling the stopwords_fetch_method proc, expected to be an array



35
36
37
# File 'lib/news_scraper/configuration.rb', line 35

def stopwords
  stopwords_fetch_method.call
end