Parent

Included Modules

Wordlist::Builder

Attributes

path[R]

Path of the word-list

file[R]

File for the word-list

Public Class Methods

build(*arguments,&block) click to toggle source

Creates a new Builder object with the given arguments, opens the word-list file, passes the builder object to the given block then finally closes the word-list file.

  Builder.build('some/path') do |builder|
    builder.parse(readline)
  end
# File lib/wordlist/builder.rb, line 39
    def self.build(*arguments,&block)
      self.new(*arguments) do |builder|
        builder.open!
        builder.build!(&block)
        builder.close!
      end
    end
new(path,&block) click to toggle source

Creates a new word-list Builder object with the specified path. If a block is given, it will be passed the newly created Builder object.

# File lib/wordlist/builder.rb, line 20
    def initialize(path,&block)
      super()

      @path = File.expand_path(path)
      @file = nil
      @filter = nil

      block.call(self) if block
    end

Public Instance Methods

+(words) click to toggle source

Add the specified words to the word-list.

# File lib/wordlist/builder.rb, line 90
    def +(words)
      words.each { |word| self << word }
      return self
    end
<<(word) click to toggle source

Appends the specified word to the word-list file, only if it has not been previously seen.

# File lib/wordlist/builder.rb, line 77
    def <<(word)
      if @file
        @filter.pass(word) do |unique|
          @file.puts unique
        end
      end

      return self
    end
build!(&block) click to toggle source

Default to be called when the word-list is to be built, simply calls the given block.

# File lib/wordlist/builder.rb, line 69
    def build!(&block)
      block.call(self) if block
    end
close!() click to toggle source

Closes the word-list file.

# File lib/wordlist/builder.rb, line 118
    def close!
      if @file
        @file.close

        @file = nil
        @filter = nil
      end
    end
open!() click to toggle source

Opens the word-list file for writing. If the file already exists, the previous words will be used to filter future duplicate words.

# File lib/wordlist/builder.rb, line 51
    def open!
      @filter = UniqueFilter.new

      if File.file?(@path)
        File.open(@path) do |file|
          file.each_line do |line|
            @filter.saw!(line.chomp)
          end
        end
      end

      @file = File.new(@path,File::RDWR | File::CREAT | File::APPEND)
    end
parse(text) click to toggle source

Parses the specified text adding each unique word to the word-list file.

# File lib/wordlist/builder.rb, line 99
    def parse(text)
      super(text).each { |word| self << word }
    end
parse_file(path) click to toggle source

Parses the contents of the file at the specified path, adding each unique word to the word-list file.

# File lib/wordlist/builder.rb, line 107
    def parse_file(path)
      File.open(path) do |file|
        file.each_line do |line|
          parse(line)
        end
      end
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.