From 8df90fd696334e13fdf32e76ed1df292f4590e4b Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Fri, 6 Jul 2012 22:38:46 +0900 Subject: make fit_to_page MOAR readable Implement some of the feedback from devolves session on readable code - and remove some garbage that found its way into the repo --- github.app you are too convenient. --- .rvmrc | 1 + lib/axlsx/workbook/worksheet/page_setup.rb | 9 +++++++ lib/axlsx/workbook/worksheet/worksheet.rb | 9 ++++--- test/workbook/worksheet/tc_page_setup.rb | 23 ++++++++++++++--- test/workbook/worksheet/tc_worksheet.rb | 5 ++-- unzip_excel/_rels/.rels | 2 -- unzip_excel/docProps/app.xml | 2 -- unzip_excel/xl/_rels/workbook.xml.rels | 2 -- unzip_excel/xl/calcChain.xml | 2 -- unzip_excel/xl/charts/chart2.xml | 2 -- unzip_excel/xl/drawings/_rels/drawing1.xml.rels | 2 -- unzip_excel/xl/drawings/_rels/drawing2.xml.rels | 2 -- unzip_excel/xl/drawings/drawing2.xml | 33 ------------------------- unzip_excel/xl/styles.xml | 2 -- unzip_excel/xl/theme/theme1.xml | 2 -- unzip_excel/xl/worksheets/_rels/sheet2.xml.rels | 2 -- unzip_excel/xl/worksheets/_rels/sheet3.xml.rels | 2 -- 17 files changed, 38 insertions(+), 64 deletions(-) create mode 100644 .rvmrc delete mode 100644 unzip_excel/_rels/.rels delete mode 100644 unzip_excel/docProps/app.xml delete mode 100644 unzip_excel/xl/_rels/workbook.xml.rels delete mode 100644 unzip_excel/xl/calcChain.xml delete mode 100644 unzip_excel/xl/charts/chart2.xml delete mode 100644 unzip_excel/xl/drawings/_rels/drawing1.xml.rels delete mode 100644 unzip_excel/xl/drawings/_rels/drawing2.xml.rels delete mode 100644 unzip_excel/xl/drawings/drawing2.xml delete mode 100644 unzip_excel/xl/styles.xml delete mode 100644 unzip_excel/xl/theme/theme1.xml delete mode 100644 unzip_excel/xl/worksheets/_rels/sheet2.xml.rels delete mode 100644 unzip_excel/xl/worksheets/_rels/sheet3.xml.rels diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 00000000..ebac5ed5 --- /dev/null +++ b/.rvmrc @@ -0,0 +1 @@ +rvm use 1.9.3@axlsx diff --git a/lib/axlsx/workbook/worksheet/page_setup.rb b/lib/axlsx/workbook/worksheet/page_setup.rb index 10cba403..4a06e1be 100644 --- a/lib/axlsx/workbook/worksheet/page_setup.rb +++ b/lib/axlsx/workbook/worksheet/page_setup.rb @@ -92,6 +92,15 @@ module Axlsx [@fit_to_width, @fit_to_height] end + + # helper method for worksheet to determine if the page setup is configured for fit to page printing + # We treat any page set up that has a value set for fit_to_width or fit_to_height value as fit_to_page. + # @return [Boolean] + def fit_to_page? + # is there some better what to express this? + (fit_to_width != nil || fit_to_height != nil) + end + # Serializes the page settings element. # @param [String] str # @return [String] diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 5959f039..3d1bdb6c 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -89,8 +89,9 @@ module Axlsx # If you want the worksheet to fit on more pages (e.g. 2x2), set {PageSetup#fit_to_width} and {PageSetup#fit_to_height} accordingly. # @return Boolean # @see #page_setup - def fit_to_page - (@page_setup != nil && (@page_setup.fit_to_width != nil || @page_setup.fit_to_height != nil)) + def fit_to_page? + return false unless @page_setup + @page_setup.fit_to_page? end @@ -303,7 +304,7 @@ module Axlsx # @return [Boolean] def fit_to_page=(v) warn('axlsx::DEPRECIATED: Worksheet#fit_to_page has been depreciated. This value will automatically be set for you when you use PageSetup#fit_to.') - fit_to_page + fit_to_page? end @@ -530,7 +531,7 @@ module Axlsx rels = relationships str = '' str.concat "" % [XML_NS, XML_NS_R] - str.concat "" % fit_to_page if fit_to_page + str.concat "" % fit_to_page? if fit_to_page? str.concat "" % dimension unless rows.size == 0 @sheet_view.to_xml_string(str) if @sheet_view if @column_info.size > 0 diff --git a/test/workbook/worksheet/tc_page_setup.rb b/test/workbook/worksheet/tc_page_setup.rb index cdf94b65..2fdbab59 100644 --- a/test/workbook/worksheet/tc_page_setup.rb +++ b/test/workbook/worksheet/tc_page_setup.rb @@ -54,6 +54,23 @@ class TestPageSetup < Test::Unit::TestCase assert_equal(nil, @ps.scale) end + def test_default_fit_to_page? + assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) + assert(@ps.fit_to_page? == false) + end + + def test_with_height_fit_to_page? + assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) + @ps.set(:fit_to_height => 1) + assert(@ps.fit_to_page?) + end + + def test_with_width_fit_to_page? + assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) + @ps.set(:fit_to_width => 1) + assert(@ps.fit_to_page?) + end + def test_to_xml_all_values @ps.set(:fit_to_height => 1, :fit_to_width => 2, :orientation => :landscape, :paper_height => "297mm", :paper_width => "210mm", :scale => 50) doc = Nokogiri::XML.parse(@ps.to_xml_string) @@ -106,7 +123,7 @@ class TestPageSetup < Test::Unit::TestCase assert_nothing_raised { @ps.scale = 99 } assert_equal(99, @ps.scale) end - + def test_fit_to fits = @ps.fit_to(:width => 1) assert_equal([1, 9999], fits) @@ -115,7 +132,7 @@ class TestPageSetup < Test::Unit::TestCase fits = @ps.fit_to :height => 7, :width => 2 assert_equal(fits, [2, 7]) assert_raise(ArgumentError) { puts @ps.fit_to(:width => true)} - - + + end end diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index 931ec51b..ed3fdfe6 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -201,8 +201,9 @@ class TestWorksheet < Test::Unit::TestCase end def test_fit_to_page_assignation_does_nothing - @ws.fit_to_page = false - assert_equal(@ws.fit_to_page, false) + @ws.fit_to_page = true + assert_equal(@ws.fit_to_page?, false) + end def test_to_xml_string_selected diff --git a/unzip_excel/_rels/.rels b/unzip_excel/_rels/.rels deleted file mode 100644 index 0eb5a3ed..00000000 --- a/unzip_excel/_rels/.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/docProps/app.xml b/unzip_excel/docProps/app.xml deleted file mode 100644 index 660058a0..00000000 --- a/unzip_excel/docProps/app.xml +++ /dev/null @@ -1,2 +0,0 @@ - -Microsoft Macintosh Excel0falseArbeitsblätter4DeckblattMeeting-Minuten gesamtMeeting-Minuten pro AccountBestandszahlen pro Accountfalsefalsefalse14.0300 \ No newline at end of file diff --git a/unzip_excel/xl/_rels/workbook.xml.rels b/unzip_excel/xl/_rels/workbook.xml.rels deleted file mode 100644 index 56a547ee..00000000 --- a/unzip_excel/xl/_rels/workbook.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/xl/calcChain.xml b/unzip_excel/xl/calcChain.xml deleted file mode 100644 index c1e8aa1e..00000000 --- a/unzip_excel/xl/calcChain.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/xl/charts/chart2.xml b/unzip_excel/xl/charts/chart2.xml deleted file mode 100644 index 604904b3..00000000 --- a/unzip_excel/xl/charts/chart2.xml +++ /dev/null @@ -1,2 +0,0 @@ - -Geplante und aktive Meeting-Minuten (pro Account)geplant'Meeting-Minuten pro Account'!$A$3:$A$10ACME CorpMobiSaveLiveSeinUdo SchorkIT and Media 2012Nolte Home StudioLandesvorstand WJ NRWMichael Gauder'Meeting-Minuten pro Account'!$B$3:$B$10General1230.01500.0930.0450.060.060.060.0510.0aktiv'Meeting-Minuten pro Account'!$A$3:$A$10ACME CorpMobiSaveLiveSeinUdo SchorkIT and Media 2012Nolte Home StudioLandesvorstand WJ NRWMichael Gauder'Meeting-Minuten pro Account'!$C$3:$C$10General77.075.0251.0152.00.00.00.0267.0 \ No newline at end of file diff --git a/unzip_excel/xl/drawings/_rels/drawing1.xml.rels b/unzip_excel/xl/drawings/_rels/drawing1.xml.rels deleted file mode 100644 index abab7803..00000000 --- a/unzip_excel/xl/drawings/_rels/drawing1.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/xl/drawings/_rels/drawing2.xml.rels b/unzip_excel/xl/drawings/_rels/drawing2.xml.rels deleted file mode 100644 index a3fb1398..00000000 --- a/unzip_excel/xl/drawings/_rels/drawing2.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/xl/drawings/drawing2.xml b/unzip_excel/xl/drawings/drawing2.xml deleted file mode 100644 index 35577167..00000000 --- a/unzip_excel/xl/drawings/drawing2.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - 4 - 0 - 2 - 0 - - - 30 - 0 - 50 - 0 - - - - - - - - - - - - - - - - - - - diff --git a/unzip_excel/xl/styles.xml b/unzip_excel/xl/styles.xml deleted file mode 100644 index 3d2677c1..00000000 --- a/unzip_excel/xl/styles.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/xl/theme/theme1.xml b/unzip_excel/xl/theme/theme1.xml deleted file mode 100644 index a7d01483..00000000 --- a/unzip_excel/xl/theme/theme1.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/xl/worksheets/_rels/sheet2.xml.rels b/unzip_excel/xl/worksheets/_rels/sheet2.xml.rels deleted file mode 100644 index 4babdeca..00000000 --- a/unzip_excel/xl/worksheets/_rels/sheet2.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/unzip_excel/xl/worksheets/_rels/sheet3.xml.rels b/unzip_excel/xl/worksheets/_rels/sheet3.xml.rels deleted file mode 100644 index 27e1d83c..00000000 --- a/unzip_excel/xl/worksheets/_rels/sheet3.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file -- cgit v1.2.3