Class: Rassphrase::WordlistParser
- Inherits:
-
Object
- Object
- Rassphrase::WordlistParser
- Defined in:
- lib/rassphrase/wordlist_parser.rb
Overview
Parses a file into a Hash, where the key is the code, and the value is the word. The file should have an item per line, where the code and the word are separated by a space. Example: 12345 hello 12346 world 12351 foo
Class Method Summary collapse
-
.parse(file_path) ⇒ Object
Parses a file with wordlist items.
-
.parse_line(line) ⇒ Object
Parses a line into a hash with :code, and :word.
Class Method Details
.parse(file_path) ⇒ Object
Parses a file with wordlist items. A path to the file must be given as the first argument.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rassphrase/wordlist_parser.rb', line 20 def self.parse(file_path) wordlist = {} File.open(file_path, 'r') do |file| while line = file.gets parts = self.parse_line(line) wordlist[parts[:code].to_s] = parts[:word] end end return wordlist end |
.parse_line(line) ⇒ Object
Parses a line into a hash with :code, and :word.
13 14 15 16 |
# File 'lib/rassphrase/wordlist_parser.rb', line 13 def self.parse_line(line) items = line.split(' ') {:code => items[0], :word => items[1]} end |