Class: PG::TextEncoder::Inet

Inherits:
SimpleEncoder
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/text_encoder.rb

Instance Method Summary collapse

Instance Method Details

#encode(value) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/text_encoder.rb', line 40

def encode(value)
	case value
	when IPAddr
		default_prefix = (value.family == Socket::AF_INET ? 32 : 128)
		s = value.to_s
		if value.respond_to?(:prefix)
			prefix = value.prefix
		else
			range = value.to_range
			prefix  = default_prefix - Math.log(((range.end.to_i - range.begin.to_i) + 1), 2).to_i
		end
		s << "/" << prefix.to_s if prefix != default_prefix
		s
	else
		value
	end
end