Class: Wordlist::FlatFile

Inherits:
List
  • Object
show all
Defined in:
lib/wordlist/flat_file.rb

Instance Attribute Summary collapse

Attributes inherited from List

#max_length, #min_length

Instance Method Summary collapse

Methods inherited from List

#each_mutation, #each_unique, #mutate

Constructor Details

#initialize(path, options = {}, &block) ⇒ FlatFile

Opens a new FlatFile list.

Parameters:

  • path (String)

    The path to the flat file word-list read from.

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

    Additional options.



18
19
20
21
22
# File 'lib/wordlist/flat_file.rb', line 18

def initialize(path,options={},&block)
  @path = path

  super(options,&block)
end

Instance Attribute Details

#pathObject

The path to the flat-file



7
8
9
# File 'lib/wordlist/flat_file.rb', line 7

def path
  @path
end

Instance Method Details

#each_word {|word| ... } ⇒ Object

Enumerates through every word in the flat-file.

Examples:

flat_file.each_word do |word|
  puts word
end

Yields:

  • (word)

    The given block will be passed every word from the word-list.

Yield Parameters:

  • word (String)

    A word from the word-list.



38
39
40
41
42
43
44
# File 'lib/wordlist/flat_file.rb', line 38

def each_word(&block)
  File.open(@path) do |file|
    file.each_line do |line|
      yield line.chomp
    end
  end
end