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.



239
240
241
242
243
# File 'lib/innodb/data_type.rb', line 239

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.



237
238
239
# File 'lib/innodb/data_type.rb', line 237

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



237
238
239
# File 'lib/innodb/data_type.rb', line 237

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



245
246
247
248
249
250
# File 'lib/innodb/data_type.rb', line 245

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