summaryrefslogtreecommitdiffstats
path: root/lib/roo/excelx/cell/base.rb
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2019-01-14 01:40:56 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2019-01-14 01:40:56 -0500
commitdddfa903d2b856146f05ffb4415c31d6127bb5bf (patch)
treee38c2aca92b54f06ccd0185f48dc47e3e1b3d77e /lib/roo/excelx/cell/base.rb
parent8280a21a23d44aa90177e2bc041d0b8dc8556f4b (diff)
New upstream version 2.8.0upstream/2.8.0
Diffstat (limited to 'lib/roo/excelx/cell/base.rb')
-rw-r--r--lib/roo/excelx/cell/base.rb38
1 files changed, 26 insertions, 12 deletions
diff --git a/lib/roo/excelx/cell/base.rb b/lib/roo/excelx/cell/base.rb
index aea8808..51fc75f 100644
--- a/lib/roo/excelx/cell/base.rb
+++ b/lib/roo/excelx/cell/base.rb
@@ -1,13 +1,18 @@
+# frozen_string_literal: true
+
+require "roo/helpers/default_attr_reader"
+
module Roo
class Excelx
class Cell
class Base
+ extend Roo::Helpers::DefaultAttrReader
attr_reader :cell_type, :cell_value, :value
# FIXME: I think style should be deprecated. Having a style attribute
# for a cell doesn't really accomplish much. It seems to be used
# when you want to export to excelx.
- attr_reader :style
+ attr_reader_with_default default_type: :base, style: 1
# FIXME: Updating a cell's value should be able tochange the cell's type,
@@ -34,14 +39,12 @@ module Roo
attr_writer :value
def initialize(value, formula, excelx_type, style, link, coordinate)
- @link = !!link
@cell_value = value
- @cell_type = excelx_type
- @formula = formula
- @style = style
+ @cell_type = excelx_type if excelx_type
+ @formula = formula if formula
+ @style = style unless style == 1
@coordinate = coordinate
- @type = :base
- @value = link? ? Roo::Link.new(link, value) : value
+ @value = link ? Roo::Link.new(link, value) : value
end
def type
@@ -50,16 +53,16 @@ module Roo
elsif link?
:link
else
- @type
+ default_type
end
end
def formula?
- !!@formula
+ !!(defined?(@formula) && @formula)
end
def link?
- !!@link
+ Roo::Link === @value
end
alias_method :formatted_value, :value
@@ -68,9 +71,16 @@ module Roo
formatted_value
end
- # DEPRECATED: Please use link instead.
+ # DEPRECATED: Please use link? instead.
def hyperlink
- warn '[DEPRECATION] `hyperlink` is deprecated. Please use `link` instead.'
+ warn '[DEPRECATION] `hyperlink` is deprecated. Please use `link?` instead.'
+ link?
+ end
+
+ # DEPRECATED: Please use link? instead.
+ def link
+ warn '[DEPRECATION] `link` is deprecated. Please use `link?` instead.'
+ link?
end
# DEPRECATED: Please use cell_value instead.
@@ -88,6 +98,10 @@ module Roo
def empty?
false
end
+
+ def presence
+ empty? ? nil : self
+ end
end
end
end