Class: ChupaText::Decomposers::CSV

Inherits:
ChupaText::Decomposer show all
Defined in:
lib/chupa-text/decomposers/csv.rb

Instance Method Summary collapse

Methods inherited from ChupaText::Decomposer

#initialize, registry

Constructor Details

This class inherits a constructor from ChupaText::Decomposer

Instance Method Details

#decompose(data) {|text_data| ... } ⇒ Object

Yields:

  • (text_data)


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

Returns:

  • (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