Class: ChupaText::Decomposers::CSV
Instance Method Summary
collapse
#initialize, registry
Instance Method Details
#decompose(data) {|text_data| ... } ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/chupa-text/decomposers/csv.rb', line 36
def decompose(data)
text = ""
data.open do |input|
csv = ::CSV.new(input)
csv.each do |row|
text << row.join(" ")
text << "\n"
end
end
text_data = TextData.new(text, :source_data => data)
if data.need_screenshot?
text_data.screenshot = create_screenshot(data, text)
end
yield(text_data)
end
|
#target?(data) ⇒ Boolean
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/chupa-text/decomposers/csv.rb', line 25
def target?(data)
return true if data.mime_type == "text/csv"
if data.text_plain? and
(data["source-mime-types"] || []).include?("text/csv")
return false
end
data.extension == "csv"
end
|