Class: Omnizip::Models::MatchResult
- Inherits:
-
Object
- Object
- Omnizip::Models::MatchResult
- Includes:
- Enumerable
- Defined in:
- lib/omnizip/models/match_result.rb
Overview
Represents the result of pattern matching against archive entries
Contains matched entries with metadata about the matching process.
Instance Attribute Summary collapse
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#total_scanned ⇒ Object
readonly
Returns the value of attribute total_scanned.
Instance Method Summary collapse
-
#add_match(entry) ⇒ self
Add a matched entry.
-
#any? ⇒ Boolean
Check if any matches were found.
-
#count ⇒ Integer
Get the number of matches.
-
#each {|entry| ... } ⇒ Enumerator, self
Iterate over matches.
-
#first ⇒ Object?
Get first match.
-
#increment_scanned(count = 1) ⇒ self
Increment the scan counter.
-
#initialize(pattern, matches: [], total_scanned: 0) ⇒ MatchResult
constructor
Initialize a new match result.
-
#last ⇒ Object?
Get last match.
-
#match_percentage ⇒ Float
Get match percentage.
-
#match_rate ⇒ Float
Get match rate (matches/scanned).
-
#none? ⇒ Boolean
Check if no matches were found.
-
#to_a ⇒ Array
Convert to array.
-
#to_h ⇒ Hash
Get summary hash.
Constructor Details
#initialize(pattern, matches: [], total_scanned: 0) ⇒ MatchResult
Initialize a new match result
18 19 20 21 22 |
# File 'lib/omnizip/models/match_result.rb', line 18 def initialize(pattern, matches: [], total_scanned: 0) @pattern = pattern @matches = Array(matches) @total_scanned = total_scanned end |
Instance Attribute Details
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
11 12 13 |
# File 'lib/omnizip/models/match_result.rb', line 11 def matches @matches end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
11 12 13 |
# File 'lib/omnizip/models/match_result.rb', line 11 def pattern @pattern end |
#total_scanned ⇒ Object (readonly)
Returns the value of attribute total_scanned.
11 12 13 |
# File 'lib/omnizip/models/match_result.rb', line 11 def total_scanned @total_scanned end |
Instance Method Details
#add_match(entry) ⇒ self
Add a matched entry
28 29 30 31 |
# File 'lib/omnizip/models/match_result.rb', line 28 def add_match(entry) @matches << entry self end |
#any? ⇒ Boolean
Check if any matches were found
52 53 54 |
# File 'lib/omnizip/models/match_result.rb', line 52 def any? !@matches.empty? end |
#count ⇒ Integer
Get the number of matches
45 46 47 |
# File 'lib/omnizip/models/match_result.rb', line 45 def count @matches.size end |
#each {|entry| ... } ⇒ Enumerator, self
Iterate over matches
83 84 85 86 87 88 |
# File 'lib/omnizip/models/match_result.rb', line 83 def each(&block) return matches.to_enum unless block matches.each(&block) self end |
#first ⇒ Object?
Get first match
93 94 95 |
# File 'lib/omnizip/models/match_result.rb', line 93 def first @matches.first end |
#increment_scanned(count = 1) ⇒ self
Increment the scan counter
37 38 39 40 |
# File 'lib/omnizip/models/match_result.rb', line 37 def increment_scanned(count = 1) @total_scanned += count self end |
#last ⇒ Object?
Get last match
100 101 102 |
# File 'lib/omnizip/models/match_result.rb', line 100 def last @matches.last end |
#match_percentage ⇒ Float
Get match percentage
75 76 77 |
# File 'lib/omnizip/models/match_result.rb', line 75 def match_percentage match_rate * 100.0 end |
#match_rate ⇒ Float
Get match rate (matches/scanned)
66 67 68 69 70 |
# File 'lib/omnizip/models/match_result.rb', line 66 def match_rate return 0.0 if @total_scanned.zero? count.to_f / @total_scanned end |
#none? ⇒ Boolean
Check if no matches were found
59 60 61 |
# File 'lib/omnizip/models/match_result.rb', line 59 def none? @matches.empty? end |
#to_a ⇒ Array
Convert to array
107 108 109 |
# File 'lib/omnizip/models/match_result.rb', line 107 def to_a @matches.dup end |
#to_h ⇒ Hash
Get summary hash
114 115 116 117 118 119 120 121 |
# File 'lib/omnizip/models/match_result.rb', line 114 def to_h { pattern: @pattern.to_s, matches: count, scanned: @total_scanned, match_rate: match_rate, } end |