Class: Innodb::DataType::BitType

Inherits:
Object
  • Object
show all
Defined in:
lib/innodb/data_type.rb

Overview

MySQL’s Bit-Value Type (BIT).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_type, modifiers, properties) ⇒ BitType

Returns a new instance of BitType.



14
15
16
17
18
19
20
# File 'lib/innodb/data_type.rb', line 14

def initialize(base_type, modifiers, properties)
  nbits = modifiers.fetch(0, 1)
  raise "Unsupported width for BIT type." unless nbits >= 0 && nbits <= 64

  @width = (nbits + 7) / 8
  @name = Innodb::DataType.make_name(base_type, modifiers, properties)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/innodb/data_type.rb', line 11

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/innodb/data_type.rb', line 12

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



22
23
24
# File 'lib/innodb/data_type.rb', line 22

def value(data)
  "0b%b" % BinData.const_get("Uint%dbe" % (@width * 8)).read(data)
end