summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-07-20 20:47:41 +0900
committerRandy Morgan <[email protected]>2012-07-20 20:47:41 +0900
commit79ae531c006ad04274aa2f42174be421b35cbfd9 (patch)
treef3e0c760753eb17bad754587a84daf362e23f1c3
parenta8b1ada7409e18ca403ef632972f8921365f331c (diff)
downloadcaxlsx-79ae531c006ad04274aa2f42174be421b35cbfd9.tar.gz
caxlsx-79ae531c006ad04274aa2f42174be421b35cbfd9.zip
bring spec coverage back up to 100%
-rw-r--r--lib/axlsx/drawing/d_lbls.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb20
-rw-r--r--test/drawing/tc_d_lbls.rb10
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb4
4 files changed, 29 insertions, 7 deletions
diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb
index faf7017d..9777aeb5 100644
--- a/lib/axlsx/drawing/d_lbls.rb
+++ b/lib/axlsx/drawing/d_lbls.rb
@@ -23,7 +23,7 @@ module Axlsx
# creates a new DLbls object
def initialize(options={})
- @d_lbl_pos = :best_fit
+ @d_lbl_pos = :bestFit
initialize_defaults
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index f0d733c7..e81c31c7 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -514,6 +514,20 @@ module Axlsx
r.cells[col_index] if r
end
+ # shortcut method to access styles direclty from the worksheet
+ # This lets us do stuff like:
+ # @example
+ # p = Axlsx::Package.new
+ # p.workbook.add_worksheet(:name => 'foo') do |sheet|
+ # my_style = sheet.styles.add_style { :bg_color => "FF0000" }
+ # sheet.add_row ['Oh No!'], :styles => my_style
+ # end
+ # p.serialize 'foo.xlsx'
+ def styles
+ @styles ||= self.workbook.styles
+ end
+
+
private
def validate_sheet_name(name)
@@ -596,11 +610,7 @@ module Axlsx
def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end
- def styles
- @styles ||= self.workbook.styles
- end
-
- def update_column_info(cells, widths=[])
+ def update_column_info(cells, widths=[])
cells.each_with_index do |cell, index|
col = find_or_create_column_info(index)
next if widths[index] == :ignore
diff --git a/test/drawing/tc_d_lbls.rb b/test/drawing/tc_d_lbls.rb
index 49facd5c..3a61b2e8 100644
--- a/test/drawing/tc_d_lbls.rb
+++ b/test/drawing/tc_d_lbls.rb
@@ -7,12 +7,20 @@ class TestDLbls < Test::Unit::TestCase
end
def test_initialization
- assert_equal(:best_fit, @d_lbls.d_lbl_pos)
+ assert_equal(:bestFit, @d_lbls.d_lbl_pos)
Axlsx::DLbls::BOOLEAN_ATTRIBUTES.each do |attr|
assert_equal(false, @d_lbls.send(attr))
end
end
+ def test_initialization_with_optoins
+ options_hash = Hash[*[Axlsx::DLbls::BOOLEAN_ATTRIBUTES.map { |name| [name, true] }] ]
+ d_lbls = Axlsx::DLbls.new(options_hash.merge( { :d_lbl_pos => :t }))
+ Axlsx::DLbls::BOOLEAN_ATTRIBUTES.each do |attr|
+ assert_equal(true, d_lbls.send(attr), "boolean attributes set by options")
+ end
+ assert_equal(:t, d_lbls.d_lbl_pos, "d_lbl_pos set by options")
+ end
def test_d_lbl_pos
assert_raise(ArgumentError, 'invlaid label positions are rejected') { @d_lbls.d_lbl_pos = :upside_down }
assert_nothing_raised('accepts valid label position') { @d_lbls.d_lbl_pos = :ctr }
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index f5689c13..8147e18e 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -314,6 +314,10 @@ class TestWorksheet < Test::Unit::TestCase
assert(schema.validate(doc).map{ |e| puts e.message; e }.empty?, "error free validation")
end
+ def test_styles
+ assert(@ws.styles.is_a?(Axlsx::Styles), 'worksheet provides access to styles')
+ end
+
def test_to_xml_string_with_illegal_chars
nasties = "\v\u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f"
@ws.add_row [nasties]