Class: PG::TextEncoder::Inet
- Inherits:
-
SimpleEncoder
- Object
- Coder
- SimpleCoder
- SimpleEncoder
- PG::TextEncoder::Inet
- Defined in:
- lib/pg/text_encoder.rb
Constant Summary
Constants inherited from Coder
Coder::FORMAT_ERROR_MASK, Coder::FORMAT_ERROR_TO_PARTIAL, Coder::FORMAT_ERROR_TO_RAISE, Coder::FORMAT_ERROR_TO_STRING, Coder::TIMESTAMP_APP_LOCAL, Coder::TIMESTAMP_APP_UTC, Coder::TIMESTAMP_DB_LOCAL, Coder::TIMESTAMP_DB_UTC
Instance Attribute Summary
Attributes inherited from Coder
Instance Method Summary collapse
Methods inherited from Coder
#==, #dup, #flags, #flags=, #format, #format=, #initialize, #inspect, #inspect_short, #marshal_dump, #marshal_load, #oid, #oid=, #to_h
Constructor Details
This class inherits a constructor from PG::Coder
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/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 |