Class: Innodb::DataType::YearType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_type, modifiers, properties) ⇒ YearType

Returns a new instance of YearType.



256
257
258
259
260
# File 'lib/innodb/data_type.rb', line 256

def initialize(base_type, modifiers, properties)
  @width = 1
  @display_width = modifiers.fetch(0, 4)
  @name = Innodb::DataType.make_name(base_type, modifiers, properties)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



253
254
255
# File 'lib/innodb/data_type.rb', line 253

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



254
255
256
# File 'lib/innodb/data_type.rb', line 254

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



262
263
264
265
266
267
268
# File 'lib/innodb/data_type.rb', line 262

def value(data)
  year = BinData::Uint8.read(data)
  return (year % 100).to_s if @display_width != 4
  return (year + 1900).to_s if year != 0

  "0000"
end