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
8 changed files
with
50 additions
and
37 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
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 |
---|---|---|
@@ -1,31 +1,15 @@ | ||
require 'colander/invalid_file' | ||
require 'colander/parser/base' | ||
require 'roo' | ||
require 'iconv' | ||
|
||
require 'open3' | ||
module Colander | ||
module Parser | ||
class Xls < Base | ||
def parse | ||
spreadsheet = parse_file | ||
@emails = collect_emails spreadsheet | ||
rescue Exception => e | ||
raise InvalidFile.new e | ||
end | ||
|
||
protected | ||
|
||
def parse_file | ||
Excel.new(@file_path,nil,:ignore) | ||
def payload | ||
File.read(@file_path) | ||
end | ||
|
||
def collect_emails(spreadsheet) | ||
spreadsheet.sheets.map do |sheet| | ||
spreadsheet.default_sheet = sheet | ||
spreadsheet.to_yaml.scan(/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/) | ||
end.flatten | ||
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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
require 'colander/parser/base' | ||
require 'roo' | ||
|
||
require 'zip' | ||
require 'iconv' | ||
module Colander | ||
module Parser | ||
class Xlsx < Xls | ||
|
||
protected | ||
def parse_file | ||
Excelx.new(@file_path,nil,:ignore) | ||
|
||
def payload | ||
''.tap do |string| | ||
Zip::ZipInputStream::open(@file_path) do |io| | ||
while (entry = io.get_next_entry) | ||
string << io.read | ||
end | ||
end | ||
end | ||
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Colander | ||
VERSION = "0.0.3" | ||
VERSION = "0.1.0" | ||
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
$:.push File.expand_path("../lib", __FILE__) | ||
|
||
require 'colander' | ||
require 'colander' | ||
require 'pry' |
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