Skip to content

Commit

Permalink
remove some code reek
Browse files Browse the repository at this point in the history
  • Loading branch information
ringe committed Nov 18, 2015
1 parent e977cf5 commit ec5ab8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions lib/axlsx/workbook/worksheet/cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def initialize(row, value = nil, options = {})
# to get less GC cycles
type = options.delete(:type) || cell_type_from_value(value)
self.type = type unless type == :string


val = options.delete(:style)
self.style = val unless val.nil? || val == 0
val = options.delete(:formula_value)
self.formula_value = val unless val.nil?
parse_options(options)

parse_options(options)

self.value = value
value.cell = self if contains_rich_text?
Expand All @@ -64,7 +64,7 @@ def initialize(row, value = nil, options = {})
:family, :b, :i, :strike, :outline,
:shadow, :condense, :extend, :u,
:vertAlign, :sz, :color, :scheme].freeze

CELL_TYPES = [:date, :time, :float, :integer, :richtext,
:string, :boolean, :iso_8601].freeze

Expand Down Expand Up @@ -93,7 +93,7 @@ def style
def type
defined?(@type) ? @type : :string
end

# @see type
def type=(v)
RestrictionValidator.validate :cell_type, CELL_TYPES, v
Expand All @@ -104,7 +104,7 @@ def type=(v)
# The value of this cell.
# @return [String, Integer, Float, Time, Boolean] casted value based on cell's type attribute.
attr_reader :value

# @see value
def value=(v)
#TODO: consider doing value based type determination first?
Expand All @@ -115,12 +115,12 @@ def value=(v)
# @return [Boolean]
def is_text_run?
defined?(@is_text_run) && @is_text_run && !contains_rich_text?
end
end

def contains_rich_text?
type == :richtext
end

# Indicates if the cell is good for shared string table
def plain_string?
type == :string && # String typed
Expand Down Expand Up @@ -347,7 +347,7 @@ def name=(label)

# returns the name of the cell
attr_reader :name

def autowidth
return if is_formula? || value.nil?
if contains_rich_text?
Expand All @@ -363,7 +363,7 @@ def autowidth
string_width(value, font_size)
end
end

# Returns the sanatized value
# TODO find a better way to do this as it accounts for 30% of
# processing time in benchmarking...
Expand All @@ -376,17 +376,17 @@ def clean_value
end

private

def styles
row.worksheet.styles
end

# Returns the width of a string according to the current style
# This is still not perfect...
# - scaling is not linear as font sizes increase
def string_width(string, font_size)
font_scale = font_size / 10.0
(string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * (font_size/10.0)
(string.to_s.count(Worksheet::THIN_CHARS) + 3.0) * font_scale
end

# we scale the font size if bold style is applied to either the style font or
Expand Down
2 changes: 1 addition & 1 deletion test/workbook/tc_shared_strings_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_remove_control_characters_in_xml_serialization
assert @p.workbook.shared_strings.unique_cells.has_key?(nasties)

# test that none of the control characters are in the XML output for shared strings
assert_no_match /#{Axlsx::CONTROL_CHARS}/, @p.workbook.shared_strings.to_xml_string
assert_no_match(/#{Axlsx::CONTROL_CHARS}/, @p.workbook.shared_strings.to_xml_string)

# assert that the shared string was normalized to remove the control characters
assert_not_nil @p.workbook.shared_strings.to_xml_string.index("helloworld")
Expand Down

0 comments on commit ec5ab8a

Please sign in to comment.