Class: Omnizip::Extraction::PredicatePattern

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(description = "custom predicate", &predicate) {|entry| ... } ⇒ PredicatePattern

Initialize a new predicate pattern

Parameters:

  • description (String) (defaults to: "custom predicate")

    Human-readable description

  • predicate (Proc)

    Block that tests entries

Yields:

  • (entry)

    Entry to test

Yield Returns:

  • (Boolean)

    Whether entry matches

Raises:

  • (ArgumentError)


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

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 9

def description
  @description
end

#predicateObject (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

Parameters:

  • entry (Object)

    Entry to check

Returns:

  • (Boolean)


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

Parameters:

  • entry (Object)

    Entry to check (can be filename or entry object)

Returns:

  • (Boolean)


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.message}"
  false
end

#to_sString

Convert pattern to string

Returns:

  • (String)


39
40
41
# File 'lib/omnizip/extraction/predicate_pattern.rb', line 39

def to_s
  @description
end