Sha256: 5a9f887ec0b19e548721229d9be4ba351105b7f235b0f7dc9eb2fc232b00caf8

Contents?: true

Size: 1.32 KB

Versions: 43

Compression:

Stored size: 1.32 KB

Contents

#!/usr/bin/env ruby

# Rex::Struct2
module Rex
module Struct2

class Restraint

	attr_reader  :max_object, :min_object, :should_update,
	  :max_transform, :min_transform, :max_inv_transform, :min_inv_transform
	attr_writer  :max_object, :min_object, :should_update,
	  :max_transform, :min_transform, :max_inv_transform, :min_inv_transform


	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

	def min
		return if !min_object
		return min_object.value
	end

	def max
		return if !max_object
		return max_object.value
	end

	# update values if request (ie string set field to its length)
	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

end

# end Rex::Struct2
end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/struct2/restraint.rb
librex-0.0.63 lib/rex/struct2/restraint.rb
librex-0.0.54 lib/rex/struct2/restraint.rb
librex-0.0.53 lib/rex/struct2/restraint.rb
librex-0.0.52 lib/rex/struct2/restraint.rb
librex-0.0.51 lib/rex/struct2/restraint.rb
librex-0.0.50 lib/rex/struct2/restraint.rb
librex-0.0.49 lib/rex/struct2/restraint.rb
librex-0.0.48 lib/rex/struct2/restraint.rb
librex-0.0.47 lib/rex/struct2/restraint.rb
librex-0.0.46 lib/rex/struct2/restraint.rb
librex-0.0.44 lib/rex/struct2/restraint.rb
librex-0.0.43 lib/rex/struct2/restraint.rb
librex-0.0.42 lib/rex/struct2/restraint.rb
librex-0.0.41 lib/rex/struct2/restraint.rb
librex-0.0.40 lib/rex/struct2/restraint.rb
librex-0.0.39 lib/rex/struct2/restraint.rb
librex-0.0.38 lib/rex/struct2/restraint.rb
librex-0.0.37 lib/rex/struct2/restraint.rb
librex-0.0.36 lib/rex/struct2/restraint.rb