Skip to content

Commit

Permalink
Merge 54b8262 into 907c178
Browse files Browse the repository at this point in the history
  • Loading branch information
chopraanmol1 committed Jan 10, 2019
2 parents 907c178 + 54b8262 commit 7b52677
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
11 changes: 4 additions & 7 deletions lib/roo/excelx.rb
Expand Up @@ -334,7 +334,7 @@ def extract_worksheet_ids(entries, path)

wb.extract(path)
workbook_doc = Roo::Utils.load_xml(path).remove_namespaces!
workbook_doc.xpath('//sheet').map { |s| s.attributes['id'].value }
workbook_doc.xpath('//sheet').map { |s| s['id'] }
end

# Internal
Expand All @@ -360,14 +360,11 @@ def extract_worksheet_rels(entries, path)
rels_doc = Roo::Utils.load_xml(path).remove_namespaces!

relationships = rels_doc.xpath('//Relationship').select do |relationship|
worksheet_types.include? relationship.attributes['Type'].value
worksheet_types.include? relationship['Type']
end

relationships.inject({}) do |hash, relationship|
attributes = relationship.attributes
id = attributes['Id']
hash[id.value] = attributes['Target'].value
hash
relationships.each_with_object({}) do |relationship, hash|
hash[relationship['Id']] = relationship['Target']
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/roo/excelx/comments.rb
Expand Up @@ -14,7 +14,7 @@ def extract_comments

Hash[doc.xpath('//comments/commentList/comment').map do |comment|
value = (comment.at_xpath('./text/r/t') || comment.at_xpath('./text/t')).text
[::Roo::Utils.ref_to_key(comment.attributes['ref'].to_s), value]
[::Roo::Utils.ref_to_key(comment['ref'].to_s), value]
end]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/roo/excelx/relationships.rb
Expand Up @@ -17,7 +17,7 @@ def extract_relationships
return [] unless doc_exists?

Hash[doc.xpath('/Relationships/Relationship').map do |rel|
[rel.attribute('Id').text, rel]
[rel['Id'], rel]
end]
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/roo/excelx/sheet_doc.rb
Expand Up @@ -180,7 +180,7 @@ def extract_hyperlinks(relationships)

Hash[hyperlinks.map do |hyperlink|
if hyperlink.attribute('id') && (relationship = relationships[hyperlink.attribute('id').text])
[::Roo::Utils.ref_to_key(hyperlink.attributes["ref"].to_s), relationship.attribute('Target').text]
[::Roo::Utils.ref_to_key(hyperlink["ref"].to_s), relationship['Target']]
end
end.compact]
end
Expand Down Expand Up @@ -220,7 +220,7 @@ def extract_cells(relationships)

def extract_dimensions
Roo::Utils.each_element(@path, 'dimension') do |dimension|
return dimension.attributes["ref"].value
return dimension["ref"]
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/roo/utils_spec.rb
Expand Up @@ -95,21 +95,21 @@
expect(described_class.load_xml('test/files/sheet1.xml')).to be_a(Nokogiri::XML::Document)
expect(described_class.load_xml('test/files/sheet1.xml').
remove_namespaces!.xpath("/worksheet/dimension").map do |dim|
dim.attributes["ref"].value end.first).to eq "A1:B11"
dim["ref"] end.first).to eq "A1:B11"
end
end

context '.each_element' do
it 'returns the expected result' do
described_class.each_element('test/files/sheet1.xml', 'dimension') do |dim|
expect(dim.attributes["ref"].value).to eq "A1:B11"
expect(dim["ref"]).to eq "A1:B11"
end
rows = []
described_class.each_element('test/files/sheet1.xml', 'row') do |row|
rows << row
end
expect(rows.size).to eq 11
expect(rows[2].attributes["r"].value).to eq "3"
expect(rows[2]["r"]).to eq "3"
end
end
end
8 changes: 4 additions & 4 deletions test/formatters/test_xml.rb
Expand Up @@ -16,7 +16,7 @@ def test_to_xml
all_cells = init_all_cells(workbook, sheetname)
cells = xml_sheet.children.reject(&:text?)

assert_equal sheetname, xml_sheet.attribute("name").value
assert_equal sheetname, xml_sheet["name"]
assert_equal all_cells.size, cells.size

cells.each_with_index do |cell, i|
Expand All @@ -27,10 +27,10 @@ def test_to_xml
all_cells[i][:type],
]
result = [
cell.attribute("row").value,
cell.attribute("column").value,
cell["row"],
cell["column"],
cell.text,
cell.attribute("type").value,
cell["type"],
]

assert_equal expected, result
Expand Down

0 comments on commit 7b52677

Please sign in to comment.