Skip to content

Commit

Permalink
Switch from Spreadsheet::Link to Roo::Link, thus removing spreadsheet…
Browse files Browse the repository at this point in the history
… dependency.

Also change the behavior of Excelx#celltype to output :link in the proper cases.
  • Loading branch information
Empact committed Nov 17, 2014
1 parent c39bdd8 commit ee67321
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
6 changes: 1 addition & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
PATH
remote: .
specs:
roo (1.13.2)
roo (2.0.0)
nokogiri
rubyzip
spreadsheet (> 0.6.4)

GEM
remote: http://rubygems.org/
Expand All @@ -25,16 +24,13 @@ GEM
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
ruby-ole (1.2.11.6)
rubyzip (1.1.0)
safe_yaml (0.9.4)
shoulda (3.0.1)
shoulda-context (~> 1.0.0)
shoulda-matchers (~> 1.0.0)
shoulda-context (1.0.0)
shoulda-matchers (1.0.0)
spreadsheet (0.8.2)
ruby-ole (>= 1.0)
vcr (2.5.0)
webmock (1.13.0)
addressable (>= 2.2.7)
Expand Down
22 changes: 14 additions & 8 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'date'
require 'nokogiri'
require 'spreadsheet'
require 'roo/link'

class Roo::Excelx < Roo::Base
module Format
Expand Down Expand Up @@ -129,14 +129,17 @@ def method_missing(m,*args)
def cell(row, col, sheet=nil)
sheet ||= @default_sheet
read_cells(sheet)
row,col = normalize(row,col)
if celltype(row,col,sheet) == :date
yyyy,mm,dd = @cell[sheet][[row,col]].split('-')
row,col = key = normalize(row,col)
case celltype(row,col,sheet)
when :date
yyyy,mm,dd = @cell[sheet][key].split('-')
Date.new(yyyy.to_i,mm.to_i,dd.to_i)
elsif celltype(row,col,sheet) == :datetime
create_datetime_from( @cell[sheet][[row,col]] )
when :datetime
create_datetime_from(@cell[sheet][key])
when :link
Roo::Link.new(@hyperlink[sheet][key], @cell[sheet][key].to_s)
else
@cell[sheet][[row,col]]
@cell[sheet][key]
end
end

Expand Down Expand Up @@ -203,9 +206,13 @@ def font(row, col, sheet=nil)
def celltype(row,col,sheet=nil)
sheet ||= @default_sheet
read_cells(sheet)
read_hyperlinks(sheet) unless @hyperlinks_read[sheet]

key = normalize(row,col)
if @formula[sheet][key]
:formula
elsif @hyperlink[sheet] && @hyperlink[sheet][key]
:link
else
@cell_type[sheet][key]
end
Expand Down Expand Up @@ -362,7 +369,6 @@ def set_cell_values(sheet,x,y,i,v,value_type,formula,
v
end

@cell[sheet][key] = Spreadsheet::Link.new(@hyperlink[sheet][key], @cell[sheet][key].to_s) if hyperlink?(y,x+i)
@excelx_type[sheet] ||= {}
@excelx_type[sheet][key] = excelx_type
@excelx_value[sheet] ||= {}
Expand Down
15 changes: 15 additions & 0 deletions lib/roo/link.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Roo
class Link < String
attr_reader :href
alias :url :href

def initialize href='', text=href
super(text)
@href = href
end

def to_uri
URI.parse href
end
end
end
1 change: 0 additions & 1 deletion roo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency "spreadsheet", "> 0.6.4"
spec.add_runtime_dependency "nokogiri"
spec.add_runtime_dependency "rubyzip"

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/roo/excelx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

it 'returns a link with the number as a string value' do
expect(subject).to be_a(Spreadsheet::Link)
expect(subject).to be_a(Roo::Link)
expect(subject).to eq("8675309.0")
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,6 @@ def test_link_to_csv
csv_output = File.join(tempdir,'link.csv')
assert oo.to_csv(csv_output)
assert File.exists?(csv_output)
puts "OUTPUTTTT"
puts open(csv_output).read
assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/link.csv #{csv_output}`
# --strip-trailing-cr is needed because the test-file use 0A and
# the test on an windows box generates 0D 0A as line endings
Expand Down

0 comments on commit ee67321

Please sign in to comment.