Class: LocalPac::TranslationRule

Inherits:
Object
  • Object
show all
Defined in:
lib/local_pac/translation_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TranslationRule

Returns a new instance of TranslationRule.



7
8
9
10
11
12
13
# File 'lib/local_pac/translation_rule.rb', line 7

def initialize(options = {})
  @network        = IPAddr.new(options.fetch(:network))
  @requested_file = options.fetch(:requested_file)
  @rewritten_file = options.fetch(:rewritten_file)
rescue KeyError => err
  raise ArgumentError, err.message
end

Instance Attribute Details

#networkObject (readonly)

Returns the value of attribute network.



5
6
7
# File 'lib/local_pac/translation_rule.rb', line 5

def network
  @network
end

#requested_fileObject (readonly)

Returns the value of attribute requested_file.



5
6
7
# File 'lib/local_pac/translation_rule.rb', line 5

def requested_file
  @requested_file
end

#rewritten_fileObject (readonly)

Returns the value of attribute rewritten_file.



5
6
7
# File 'lib/local_pac/translation_rule.rb', line 5

def rewritten_file
  @rewritten_file
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/local_pac/translation_rule.rb', line 19

def eql?(other)
  network == other.network && requested_file == other.requested_file
end

#hashObject



23
24
25
# File 'lib/local_pac/translation_rule.rb', line 23

def hash
  [network, requested_file].hash
end

#match?(client_ip, file) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/local_pac/translation_rule.rb', line 15

def match?(client_ip, file)
  network.include?(client_ip) && requested_file == file
end