Class: Lapis::Minecraft::Versioning::OSRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/lapis/minecraft/versioning/os_rule.rb

Overview

Description of how resources can be chosen for operating systems.

Instance Attribute Summary collapse

Attributes inherited from Rule

#allowed?

Instance Method Summary collapse

Constructor Details

#initialize(is_allowed, os_type, os_version = nil) ⇒ OSRule

Creates an OS rule.


25
26
27
28
29
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 25

def initialize(is_allowed, os_type, os_version = nil)
  super(is_allowed)
  @os_type = os_type
  @os_version = os_version ? Regexp.new(os_version) : // # Use empty regex if no version specified.
end

Instance Attribute Details

#os_typeSymbol (readonly)

Type of operating system this rule applies to.


12
13
14
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 12

def os_type
  @os_type
end

#os_versionRegexp (readonly)

Operating system version regex. This rule should apply if the OS version matches this regex.


17
18
19
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 17

def os_version
  @os_version
end

Instance Method Details

#==(other) ⇒ true, false

Compares one rule to another.


47
48
49
50
51
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 47

def ==(other)
  super(other) &&
      other.os_type == @os_type &&
      other.os_version == @os_version
end

#applies_to?(properties) ⇒ true, false

Checks whether the rule applies to a set of properties.

Options Hash (properties):

  • :os_type (String)

    One of: windows, linux, or osx.

  • :os_version (String)

    Version of the OS.


37
38
39
40
41
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 37

def applies_to?(properties)
  super(properties) &&
      properties[:os_type].downcase == @os_type.to_s &&
      @os_version.match(properties[:os_version])
end