Class: Ronin::Wordlists::CLI::WordlistIndex Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/wordlists/cli/wordlist_index.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents an index of known wordlists.

Defined Under Namespace

Classes: Entry, InvalidSchema

Constant Summary collapse

PATH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Path to the builtin wordlists.yml index file.

File.join(ROOT,'data','wordlists.yml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries) ⇒ WordlistIndex

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the wordlist index.

Parameters:

  • entries (Hash{String => Entry})

    The entries for the wordlist index.



98
99
100
# File 'lib/ronin/wordlists/cli/wordlist_index.rb', line 98

def initialize(entries)
  @entries = entries
end

Instance Attribute Details

#entriesHash{String => Entry} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The entries in the wordlist index.

Returns:

  • (Hash{String => Entry})


90
91
92
# File 'lib/ronin/wordlists/cli/wordlist_index.rb', line 90

def entries
  @entries
end

Class Method Details

.load(path = PATH) ⇒ WordlistIndex

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Loads the wordlist index file from the given path.

Parameters:

  • path (String) (defaults to: PATH)

    The path of the wordlit index file.

Returns:

Raises:

  • (InvalidSchema)

    The wordlist index file has an invalid schema.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ronin/wordlists/cli/wordlist_index.rb', line 123

def self.load(path=PATH)
  yaml = YAML.load_file(path)

  unless yaml.kind_of?(Hash)
    raise(InvalidSchema,"wordlist index file does not contain a Hash: #{path.inspect}")
  end

  entries = yaml.to_h do |name,attributes|
    unless attributes[:url]
      raise(InvalidSchema,"wordlist index entry does not have a URL: #{name.inspect}")
    end

    unless attributes[:summary]
      raise(InvalidSchema,"wordlist index entry does not have a summary: #{name.inspect}")
    end

    [name, Entry.new(name,**attributes)]
  end

  return new(entries)
end

Instance Method Details

#[](name) ⇒ Entry?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Looks up the wordlist by name within the wordlist index.

Parameters:

  • name (String)

    The wordlist name.

Returns:

  • (Entry, nil)

    The entry for the wordlist.



154
155
156
# File 'lib/ronin/wordlists/cli/wordlist_index.rb', line 154

def [](name)
  @entries[name]
end

#each {|entry| ... } ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enumerates over every entry in the wordlist index.

Yields:

  • (entry)

    If a block is given, it will be passed every entry in the wordlist index.

Yield Parameters:

  • entry (Entry)

    An entry in the wordlist index.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned instead.



171
172
173
# File 'lib/ronin/wordlists/cli/wordlist_index.rb', line 171

def each(&block)
  @entries.each_value(&block)
end