Class: Omnizip::Extraction::PredicatePattern
- Inherits:
-
Object
- Object
- Omnizip::Extraction::PredicatePattern
- Defined in:
- lib/omnizip/extraction/predicate_pattern.rb
Overview
Implements custom predicate pattern matching for archive entries
Allows using arbitrary Ruby blocks to determine if an entry matches.
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#predicate ⇒ Object
readonly
Returns the value of attribute predicate.
Instance Method Summary collapse
-
#call(entry) ⇒ Boolean
Call the predicate directly.
-
#initialize(description = "custom predicate", &predicate) {|entry| ... } ⇒ PredicatePattern
constructor
Initialize a new predicate pattern.
-
#match?(entry) ⇒ Boolean
Check if an entry matches the predicate.
-
#to_s ⇒ String
Convert pattern to string.
Constructor Details
#initialize(description = "custom predicate", &predicate) {|entry| ... } ⇒ PredicatePattern
Initialize a new predicate pattern
17 18 19 20 21 22 |
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 17 def initialize(description = "custom predicate", &predicate) raise ArgumentError, "Block required" unless predicate @description = description @predicate = predicate end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 9 def description @description end |
#predicate ⇒ Object (readonly)
Returns the value of attribute predicate.
9 10 11 |
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 9 def predicate @predicate end |
Instance Method Details
#call(entry) ⇒ Boolean
Call the predicate directly
47 48 49 |
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 47 def call(entry) match?(entry) end |
#match?(entry) ⇒ Boolean
Check if an entry matches the predicate
28 29 30 31 32 33 34 |
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 28 def match?(entry) @predicate.call(entry) rescue StandardError => e # If predicate raises error, treat as non-match warn "Predicate error for #{entry}: #{e.}" false end |
#to_s ⇒ String
Convert pattern to string
39 40 41 |
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 39 def to_s @description end |