Class: ChupaText::Formatters::Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/chupa-text/formatters/hash.rb

Direct Known Subclasses

JSON, MIME

Instance Method Summary collapse

Constructor Details

#initializeHash

Returns a new instance of Hash.



20
21
22
# File 'lib/chupa-text/formatters/hash.rb', line 20

def initialize
  @texts = []
end

Instance Method Details

#format_extracted(data) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



44
45
46
47
48
49
# 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) ⇒ Object



24
25
# File 'lib/chupa-text/formatters/hash.rb', line 24

def format_start(data)
end