Method: WordCounter#initialize

Defined in:
lib/word_counter.rb

#initialize(arg, show_sentences = false, colorize = false) ⇒ WordCounter

WordCounter!

Parameters:

  • The path and filename of the file to analyze

  • (defaults to: false)

    (default: false) If true, WordCounter will print out the sentences which contain the counted word in question

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/word_counter.rb', line 17

def initialize arg, show_sentences = false, colorize = false
  raise ArgumentError, "Please supply a URL or file path." unless arg
  @show_sentences = show_sentences
  @colorize = colorize

  begin
    # try to open it as a file
    @hashified_words = WordCounter.analyze_file arg
  rescue NoFileError => e
    # try to analyze it as a website, so curl it
    @hashified_words = WordCounter.analyze_website arg
  end
end