class ChupaText::Formatters::Hash

Public Class Methods

new() click to toggle source
# File lib/chupa-text/formatters/hash.rb, line 20
def initialize
  @texts = []
end

Public Instance Methods

format_extracted(data) click to toggle source
# File lib/chupa-text/formatters/hash.rb, line 27
def format_extracted(data)
  text = {}
  format_headers(data, text)
  text["body"] = data.body
  screenshot = data.screenshot
  if screenshot
    text["screenshot"] = {
      "mime-type" => screenshot.mime_type,
      "data" => screenshot.data,
    }
    if screenshot.encoding
      text["screenshot"]["encoding"] = screenshot.encoding
    end
  end
  @texts << text
end
format_finish(data) click to toggle source
# File lib/chupa-text/formatters/hash.rb, line 44
def format_finish(data)
  formatted = {}
  format_headers(data, formatted)
  formatted["texts"] = @texts
  formatted
end
format_start(data) click to toggle source
# File lib/chupa-text/formatters/hash.rb, line 24
def format_start(data)
end

Private Instance Methods

format_header(name, value, target) click to toggle source
# File lib/chupa-text/formatters/hash.rb, line 67
def format_header(name, value, target)
  return if value.nil?
  target[name] = value
end
format_headers(data, target) click to toggle source
# File lib/chupa-text/formatters/hash.rb, line 52
def format_headers(data, target)
  format_header("mime-type", data.mime_type, target)
  format_header("uri",       data.uri,       target)
  case data.uri
  when URI::HTTP, URI::FTP, nil
    # No path
  else
    format_header("path",    data.path,      target)
  end
  format_header("size",      data.size,      target)
  data.attributes.each do |name, value|
    format_header(name, value, target)
  end
end