Class: Roo::Excelx::Cell::Time

Inherits:
DateTime show all
Defined in:
lib/roo/excelx/cell/time.rb

Constant Summary

Constants inherited from DateTime

DateTime::SECONDS_IN_DAY

Instance Attribute Summary collapse

Attributes inherited from Base

#cell_type

Instance Method Summary collapse

Methods inherited from Base

#empty?, #excelx_type, #excelx_value, #formula?, #hyperlink, #link, #link?, #presence, #type

Methods included from Helpers::DefaultAttrReader

#attr_reader_with_default

Constructor Details

#initialize(value, formula, excelx_type, style, link, base_date, coordinate) ⇒ Time

Returns a new instance of Time.



11
12
13
14
15
16
17
# File 'lib/roo/excelx/cell/time.rb', line 11

def initialize(value, formula, excelx_type, style, link, base_date, coordinate)
  # NOTE: Pass all arguments to DateTime super class.
  super
  @format = excelx_type.last
  @datetime = create_datetime(base_date, value)
  @value = link ? Roo::Link.new(link, value) : (value.to_f * 86_400).to_i
end

Instance Attribute Details

#cell_valueObject (readonly)

Returns the value of attribute cell_value.



7
8
9
# File 'lib/roo/excelx/cell/time.rb', line 7

def cell_value
  @cell_value
end

#coordinateObject (readonly)

Returns the value of attribute coordinate.



7
8
9
# File 'lib/roo/excelx/cell/time.rb', line 7

def coordinate
  @coordinate
end

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/roo/excelx/cell/time.rb', line 7

def format
  @format
end

#formulaObject (readonly)

Returns the value of attribute formula.



7
8
9
# File 'lib/roo/excelx/cell/time.rb', line 7

def formula
  @formula
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/roo/excelx/cell/time.rb', line 7

def value
  @value
end

Instance Method Details

#formatted_valueObject Also known as: to_s



19
20
21
22
# File 'lib/roo/excelx/cell/time.rb', line 19

def formatted_value
  formatter = @format.gsub(/#{TIME_FORMATS.keys.join('|')}/, TIME_FORMATS)
  @datetime.strftime(formatter)
end