Class: Omnizip::Models::ExtractionRule

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/models/extraction_rule.rb

Overview

Represents a rule for extracting files from an archive

Defines what files to extract and how to extract them using patterns, predicates, and options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patterns: [], predicates: [], options: {}) ⇒ ExtractionRule

Initialize a new extraction rule

Parameters:

  • patterns (Array<String, Regexp>) (defaults to: [])

    Patterns to match

  • predicates (Array<Proc>) (defaults to: [])

    Custom predicates for matching

  • options (Hash) (defaults to: {})

    Extraction options

Options Hash (options:):

  • :preserve_paths (Boolean)

    Keep directory structure

  • :flatten (Boolean)

    Extract all to destination root

  • :overwrite (Boolean)

    Overwrite existing files

  • :dest_prefix (String)

    Prefix for destination paths



21
22
23
24
25
# File 'lib/omnizip/models/extraction_rule.rb', line 21

def initialize(patterns: [], predicates: [], options: {})
  @patterns = Array(patterns)
  @predicates = Array(predicates)
  @options = default_options.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/omnizip/models/extraction_rule.rb', line 10

def options
  @options
end

#patternsObject (readonly)

Returns the value of attribute patterns.



10
11
12
# File 'lib/omnizip/models/extraction_rule.rb', line 10

def patterns
  @patterns
end

#predicatesObject (readonly)

Returns the value of attribute predicates.



10
11
12
# File 'lib/omnizip/models/extraction_rule.rb', line 10

def predicates
  @predicates
end

Instance Method Details

#[](key) ⇒ Object

Get option value

Parameters:

  • key (Symbol)

    Option key

Returns:

  • (Object)

    Option value



70
71
72
# File 'lib/omnizip/models/extraction_rule.rb', line 70

def [](key)
  @options[key]
end

#[]=(key, value) ⇒ Object

Set option value

Parameters:

  • key (Symbol)

    Option key

  • value (Object)

    Option value



78
79
80
# File 'lib/omnizip/models/extraction_rule.rb', line 78

def []=(key, value)
  @options[key] = value
end

#add_pattern(pattern) ⇒ self

Add a pattern to the rule

Parameters:

  • pattern (String, Regexp)

    Pattern to add

Returns:

  • (self)


31
32
33
34
# File 'lib/omnizip/models/extraction_rule.rb', line 31

def add_pattern(pattern)
  @patterns << pattern
  self
end

#add_predicate(&predicate) ⇒ self

Add a predicate to the rule

Parameters:

  • predicate (Proc)

    Predicate block to add

Returns:

  • (self)


40
41
42
43
# File 'lib/omnizip/models/extraction_rule.rb', line 40

def add_predicate(&predicate)
  @predicates << predicate if predicate
  self
end

#conditions?Boolean

Check if the rule has any conditions

Returns:

  • (Boolean)


62
63
64
# File 'lib/omnizip/models/extraction_rule.rb', line 62

def conditions?
  patterns? || predicates?
end

#flatten?Boolean

Check if paths should be flattened

Returns:

  • (Boolean)


92
93
94
# File 'lib/omnizip/models/extraction_rule.rb', line 92

def flatten?
  @options[:flatten]
end

#overwrite?Boolean

Check if existing files should be overwritten

Returns:

  • (Boolean)


99
100
101
# File 'lib/omnizip/models/extraction_rule.rb', line 99

def overwrite?
  @options[:overwrite]
end

#patterns?Boolean

Check if any patterns are defined

Returns:

  • (Boolean)


48
49
50
# File 'lib/omnizip/models/extraction_rule.rb', line 48

def patterns?
  !@patterns.empty?
end

#predicates?Boolean

Check if any predicates are defined

Returns:

  • (Boolean)


55
56
57
# File 'lib/omnizip/models/extraction_rule.rb', line 55

def predicates?
  !@predicates.empty?
end

#preserve_paths?Boolean

Check if paths should be preserved

Returns:

  • (Boolean)


85
86
87
# File 'lib/omnizip/models/extraction_rule.rb', line 85

def preserve_paths?
  @options[:preserve_paths]
end