Class: Nosy::Output

Inherits:
Object
  • Object
show all
Includes:
HtmlHelpers
Defined in:
lib/nosy/output.rb,
lib/nosy/output/html_helpers.rb

Defined Under Namespace

Modules: HtmlHelpers

Instance Method Summary collapse

Methods included from HtmlHelpers

#css, #generate_html, #head, #html_text, #imessage_or_sms, #sender_html

Instance Method Details

#to_csv(texts, output = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/nosy/output.rb', line 30

def to_csv( texts, output=nil )
  CSV.open("iphone-texts.csv", "w") do |csv|
    csv << ["id", "date", "sender", "receiver", "message", "imessage"]
    texts.each_with_index do |text, index|
      csv << [index+1, text.date, text.sender, text.receiver, text.message, text.imessage]
    end
  end
  "#{Dir.pwd}/iphone-texts.csv"
end

#to_hash(texts) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/nosy/output.rb', line 40

def to_hash (texts)
  hash = {}
  texts.each_with_index do |m, index|
    hash["#{index}"] = { date: m.date, sender: m.sender, receiver: m.receiver, message: m.message, imessage: m.imessage }
  end
  hash
end

#to_html(texts) ⇒ Object



10
11
12
13
14
15
# File 'lib/nosy/output.rb', line 10

def to_html( texts )
  File.open("iphone-texts.html","w") do |f|
    generate_html(f, texts)
  end
  "#{Dir.pwd}/iphone-texts.html"
end

#to_json(texts, file = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nosy/output.rb', line 17

def  to_json( texts, file=false )
  hash = to_hash(texts)

  if file == true
    File.open("iphone-texts.json","w") do |f|
      f.write(hash.to_json)
    end
    "#{Dir.pwd}/iphone-texts.json"
  else
    hash.to_json
  end
end