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)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chupa-text/decomposers/csv.rb', line 29

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)
  text_data.uri = data.uri
  yield(text_data)
end

#target?(data) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/chupa-text/decomposers/csv.rb', line 24

def target?(data)
  data.extension == "csv" or
    data.mime_type == "text/csv"
end