Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Roo | ||
class Excelx | ||
class Drawing | ||
class Base | ||
# extend Roo::Helpers::DefaultAttrReader | ||
attr_reader :value, :coordinate | ||
|
||
def initialize(type, value, coordinate) | ||
@type = type | ||
@value = value | ||
@coordinate = coordinate | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Roo | ||
class Excelx | ||
class Drawing | ||
class Checkbox < Roo::Excelx::Drawing::Base | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Roo | ||
class Excelx | ||
class Drawing | ||
class Unknown < Roo::Excelx::Drawing::Base | ||
attr_reader :type | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'roo/excelx/extractor' | ||
require 'roo/excelx/drawing/base' | ||
require 'roo/excelx/drawing/checkbox' | ||
require 'roo/excelx/drawing/unknown' | ||
|
||
module Roo | ||
class Excelx | ||
class Drawings < Excelx::Extractor | ||
# Returns: Hash { id1: extracted_file_name1 }, | ||
# Example: { "rId1"=>"roo_media_image1.png", | ||
# "rId2"=>"roo_media_image2.png", | ||
# "rId3"=>"roo_media_image3.png" } | ||
def list | ||
@drawings ||= extract_drawings | ||
end | ||
|
||
private | ||
|
||
def extract_drawings | ||
return {} unless doc_exists? | ||
|
||
doc.xpath('//shape').each_with_object({}) do |shape, hash| | ||
client_data = shape.xpath('./ClientData').first | ||
anchors = client_data.xpath('./Anchor').text | ||
coords = Utils.anchor_to_coordinates(anchors) | ||
|
||
hash[coords] = create_drawing( | ||
client_data['ObjectType'], | ||
client_data, | ||
coords | ||
) | ||
end | ||
end | ||
|
||
|
||
def create_drawing(type, client_data, coords) | ||
case type | ||
when 'Checkbox' | ||
Drawing::Checkbox.new(type, client_data.xpath('./Checked').any?, coords) | ||
else | ||
Drawing::Unknown.new(type, nil, coords) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.