Class: Innodb::DataType::IntegerType
- Inherits:
-
Object
- Object
- Innodb::DataType::IntegerType
- Defined in:
- lib/innodb/data_type.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #base_type_width_map ⇒ Object
- #get_int(data, nbits) ⇒ Object
- #get_uint(data, nbits) ⇒ Object
-
#initialize(base_type, modifiers, properties) ⇒ IntegerType
constructor
A new instance of IntegerType.
- #value(data) ⇒ Object
Constructor Details
#initialize(base_type, modifiers, properties) ⇒ IntegerType
Returns a new instance of IntegerType.
28 29 30 31 32 |
# File 'lib/innodb/data_type.rb', line 28 def initialize(base_type, modifiers, properties) @width = base_type_width_map[base_type] @unsigned = properties.include?(:UNSIGNED) @name = Innodb::DataType.make_name(base_type, modifiers, properties) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/innodb/data_type.rb', line 26 def name @name end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
26 27 28 |
# File 'lib/innodb/data_type.rb', line 26 def width @width end |
Instance Method Details
#base_type_width_map ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/innodb/data_type.rb', line 34 def base_type_width_map { :BOOL => 1, :BOOLEAN => 1, :TINYINT => 1, :SMALLINT => 2, :MEDIUMINT => 3, :INT => 4, :INT6 => 6, :BIGINT => 8, } end |
#get_int(data, nbits) ⇒ Object
56 57 58 |
# File 'lib/innodb/data_type.rb', line 56 def get_int(data, nbits) BinData::const_get("Int%dbe" % nbits).read(data) ^ (-1 << (nbits - 1)) end |
#get_uint(data, nbits) ⇒ Object
52 53 54 |
# File 'lib/innodb/data_type.rb', line 52 def get_uint(data, nbits) BinData::const_get("Uint%dbe" % nbits).read(data) end |
#value(data) ⇒ Object
47 48 49 50 |
# File 'lib/innodb/data_type.rb', line 47 def value(data) nbits = @width * 8 @unsigned ? get_uint(data, nbits) : get_int(data, nbits) end |