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.



233
234
235
236
237
# File 'lib/innodb/data_type.rb', line 233

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.



231
232
233
# File 'lib/innodb/data_type.rb', line 231

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



231
232
233
# File 'lib/innodb/data_type.rb', line 231

def width
  @width
end

Instance Method Details

#value(data) ⇒ Object



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

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