Class: Omnizip::Profile::CustomProfile::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/profile/custom_profile.rb

Overview

Builder for creating custom profiles

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, base_profile = nil) ⇒ Builder

Initialize a new builder

Parameters:

  • name (Symbol)

    Profile name

  • base_profile (CompressionProfile, nil) (defaults to: nil)

    Base profile to extend



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/omnizip/profile/custom_profile.rb', line 19

def initialize(name, base_profile = nil)
  @name = name

  if base_profile
    # Inherit settings from base profile
    @algorithm = base_profile.algorithm
    @level = base_profile.level
    @filter = base_profile.filter
    @solid = base_profile.solid
    @description = base_profile.description
    @base_profile = base_profile
  else
    # Default settings
    @algorithm = :deflate
    @level = 6
    @filter = nil
    @solid = false
    @description = ""
    @base_profile = nil
  end
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



12
13
14
# File 'lib/omnizip/profile/custom_profile.rb', line 12

def algorithm
  @algorithm
end

#base_profileObject

Returns the value of attribute base_profile.



12
13
14
# File 'lib/omnizip/profile/custom_profile.rb', line 12

def base_profile
  @base_profile
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/omnizip/profile/custom_profile.rb', line 12

def description
  @description
end

#filterObject

Returns the value of attribute filter.



12
13
14
# File 'lib/omnizip/profile/custom_profile.rb', line 12

def filter
  @filter
end

#levelObject

Returns the value of attribute level.



12
13
14
# File 'lib/omnizip/profile/custom_profile.rb', line 12

def level
  @level
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/omnizip/profile/custom_profile.rb', line 12

def name
  @name
end

#solidObject

Returns the value of attribute solid.



12
13
14
# File 'lib/omnizip/profile/custom_profile.rb', line 12

def solid
  @solid
end

Instance Method Details

#buildCustomProfile

Build the custom profile

Returns:



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/omnizip/profile/custom_profile.rb', line 44

def build
  CustomProfile.new(
    name: name,
    algorithm: algorithm,
    level: level,
    filter: filter,
    solid: solid,
    description: description,
    base_profile: base_profile,
  )
end

#valid?Boolean

Validate builder settings

Returns:

  • (Boolean)

    true if valid

Raises:

  • (ArgumentError)

    if settings are invalid



60
61
62
63
64
65
66
# File 'lib/omnizip/profile/custom_profile.rb', line 60

def valid?
  validate_name!
  validate_algorithm!
  validate_level!
  validate_filter!
  true
end