Class: Wordlist::File
- Inherits:
-
AbstractWordlist
- Object
- AbstractWordlist
- Wordlist::File
- Defined in:
- lib/wordlist/file.rb
Overview
Instance Attribute Summary collapse
-
#format ⇒ :txt, ...
readonly
The format of the wordlist file.
-
#path ⇒ Object
readonly
The path to the
.txt
file.
Class Method Summary collapse
-
.open(path, **kwargs) {|wordlist| ... } ⇒ File
Opens a wordlist file.
-
.read(path, **kwargs) {|word| ... } ⇒ Enumerator
Opens and reads the wordlist file.
Instance Method Summary collapse
-
#each {|word| ... } ⇒ Enumerator
Enumerates through every word in the
.txt
file. -
#each_line {|line| ... } ⇒ Enumerator
Enumerates through each line in the
.txt
file wordlist. -
#initialize(path, format: Format.infer(path)) ⇒ File
constructor
Opens a wordlist file.
Methods included from ListMethods
#capitalize, #concat, #downcase, #gsub, #intersect, #mutate, #mutate_case, #power, #product, #sub, #subtract, #tr, #union, #uniq, #upcase
Constructor Details
#initialize(path, format: Format.infer(path)) ⇒ File
Opens a wordlist file.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wordlist/file.rb', line 48 def initialize(path, format: Format.infer(path)) @path = ::File.(path) @format = format unless ::File.file?(@path) raise(WordlistNotFound,"wordlist file does not exist: #{@path.inspect}") end unless Format::FORMATS.include?(@format) raise(UnknownFormat,"unknown format given: #{@format.inspect}") end end |
Instance Attribute Details
#format ⇒ :txt, ... (readonly)
The format of the wordlist file.
28 29 30 |
# File 'lib/wordlist/file.rb', line 28 def format @format end |
#path ⇒ Object (readonly)
The path to the .txt
file
23 24 25 |
# File 'lib/wordlist/file.rb', line 23 def path @path end |
Class Method Details
.open(path, **kwargs) {|wordlist| ... } ⇒ File
Opens a wordlist file.
80 81 82 83 84 |
# File 'lib/wordlist/file.rb', line 80 def self.open(path,**kwargs) wordlist = new(path,**kwargs) yield wordlist if block_given? return wordlist end |
.read(path, **kwargs) {|word| ... } ⇒ Enumerator
Opens and reads the wordlist file.
101 102 103 |
# File 'lib/wordlist/file.rb', line 101 def self.read(path,**kwargs,&block) open(path,**kwargs).each(&block) end |
Instance Method Details
#each {|word| ... } ⇒ Enumerator
Note:
Empty lines and lines beginning with #
characters will be ignored.
Enumerates through every word in the .txt
file.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/wordlist/file.rb', line 147 def each return enum_for(__method__) unless block_given? each_line do |line| line.chomp! unless (line.empty? || line.start_with?('#')) yield line end end end |
#each_line {|line| ... } ⇒ Enumerator
Enumerates through each line in the .txt
file wordlist.
119 120 121 122 123 |
# File 'lib/wordlist/file.rb', line 119 def each_line(&block) return enum_for(__method__) unless block open { |io| io.each_line(&block) } end |