Class: Rex::Struct2::Restraint

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/struct2/restraint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_object = nil, min_object = nil, should_update = false, max_transform = nil, min_transform = nil, max_inv_transform = nil, min_inv_transform = nil) ⇒ Restraint

Returns a new instance of Restraint.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rex/struct2/restraint.rb', line 15

def initialize(
  max_object=nil, min_object=nil, should_update=false,
  max_transform=nil, min_transform=nil,
  max_inv_transform=nil, min_inv_transform=nil
)
  @max_object    = max_object
  @min_object    = min_object
  @should_update = should_update

  def_trans = proc {|i| i}

  @max_transform       = max_transform == nil ? def_trans : max_transform
  @min_transform       = min_transform == nil ? def_trans : min_transform
  @max_inv_transform   = max_inv_transform == nil ? def_trans : max_inv_transform
  @min_inv_transform   = min_inv_transform == nil ? def_trans : min_inv_transform
end

Instance Attribute Details

#max_inv_transformObject

Returns the value of attribute max_inv_transform.



9
10
11
# File 'lib/rex/struct2/restraint.rb', line 9

def max_inv_transform
  @max_inv_transform
end

#max_objectObject

Returns the value of attribute max_object.



9
10
11
# File 'lib/rex/struct2/restraint.rb', line 9

def max_object
  @max_object
end

#max_transformObject

Returns the value of attribute max_transform.



9
10
11
# File 'lib/rex/struct2/restraint.rb', line 9

def max_transform
  @max_transform
end

#min_inv_transformObject

Returns the value of attribute min_inv_transform.



9
10
11
# File 'lib/rex/struct2/restraint.rb', line 9

def min_inv_transform
  @min_inv_transform
end

#min_objectObject

Returns the value of attribute min_object.



9
10
11
# File 'lib/rex/struct2/restraint.rb', line 9

def min_object
  @min_object
end

#min_transformObject

Returns the value of attribute min_transform.



9
10
11
# File 'lib/rex/struct2/restraint.rb', line 9

def min_transform
  @min_transform
end

#should_updateObject

Returns the value of attribute should_update.



9
10
11
# File 'lib/rex/struct2/restraint.rb', line 9

def should_update
  @should_update
end

Instance Method Details

#maxObject



37
38
39
40
# File 'lib/rex/struct2/restraint.rb', line 37

def max
  return if !max_object
  return max_object.value
end

#minObject



32
33
34
35
# File 'lib/rex/struct2/restraint.rb', line 32

def min
  return if !min_object
  return min_object.value
end

#update(value) ⇒ Object

update values if request (ie string set field to its length)



43
44
45
46
47
48
# File 'lib/rex/struct2/restraint.rb', line 43

def update(value)
  return if !@should_update

  max_object.value = max_inv_transform.call(value) if max_object
  min_object.value = min_inv_transform.call(value) if min_object
end