Class: IABConsentString::Util::Utils
- Inherits:
-
Object
- Object
- IABConsentString::Util::Utils
- Defined in:
- lib/iab_consent_string/util/utils.rb
Class Method Summary collapse
-
.fromBinaryString(binaryString) ⇒ Bits
Create bit buffer from string representation.
Class Method Details
.fromBinaryString(binaryString) ⇒ Bits
Create bit buffer from string representation
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/iab_consent_string/util/utils.rb', line 9 def self.fromBinaryString(binaryString) length = binaryString.length bitsFit = (length % 8) == 0 str = "" for i in (0...length / 8 + (bitsFit ? 0 : 1)) do str << 0b00000000 end bits = IABConsentString::Bits.new(str.bytes.to_a) for i in (0...length) do if binaryString[i] == '1' bits.setBit(i) else bits.unsetBit(i) end end bits end |