Module: WordsCounted

Defined in:
lib/words_counted.rb,
lib/words_counted/counter.rb,
lib/words_counted/version.rb,
lib/words_counted/tokeniser.rb,
lib/words_counted/deprecated.rb

Defined Under Namespace

Modules: Deprecated Classes: Counter, Tokeniser

Constant Summary collapse

VERSION =
"1.0.3"

Class Method Summary collapse

Class Method Details

.count(input, options = {}) ⇒ WordsCounted::Counter

Takes a string, tokenises it, and returns an instance of Counter with the resulting tokens.

Parameters:

  • input (String)

    The input to be tokenised

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

    The options to pass onto Counter

Returns:

See Also:



25
26
27
28
# File 'lib/words_counted.rb', line 25

def self.count(input, options = {})
  tokens = Tokeniser.new(input).tokenise(**options)
  Counter.new(tokens)
end

.from_file(path, options = {}) ⇒ WordsCounted::Counter

Takes a file path, reads the file and tokenises its contents, and returns an instance of Counter with the resulting tokens.

Parameters:

  • path (String)

    The file to be read and tokenised

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

    The options to pass onto Counter

Returns:

See Also:



39
40
41
42
43
44
# File 'lib/words_counted.rb', line 39

def self.from_file(path, options = {})
  tokens = File.open(path) do |file|
    Tokeniser.new(file.read).tokenise(**options)
  end
  Counter.new(tokens)
end