# Inserting hash data into email

**URL:** <https://www.ruby-forum.com/t/inserting-hash-data-into-email/138025>\
**Category:** Ruby\
**Created:** [May 19, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/inserting-hash-data-into-email/138025 "2008-05-19T16:36:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![twaters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a6a055/32.png) [@twaters](https://www.ruby-forum.com/u/twaters)\
**Post date:** [May 19, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/inserting-hash-data-into-email/138025/1 "2008-05-19T16:36:38Z")

</div>

Morning all,

What is the best way to insert hash data into an email? I have tried  
several different ways and I either get can’t convert array to a string  
or private method â€˜chompâ€™. Below is the code I am currently using.

Tim

class SktyFut  
attr\_reader :acct

def initialize(filename)  
@acct = File.new(filename, “r”)  
end

def future\_data  
@sktylist = Hash.new(0)  
@acct.each do |list|  
office = list[21…23]  
if office == “RPT”  
next  
else  
acctnum = list[24…28]  
end  
lv = list[217…230]  
is\_negative = list[215,1] == “-”  
value = lv.to\_f/100  
value = -value if is\_negative

```
  # Add vales to hash

  @sktylist[acctnum] += value
end
return @sktylist

```

end  
end

class Calculate  
attr\_reader :sktyfuta, :sktyfutb  
def initialize(sktyfuta, sktyfutb)  
@sktyfuta = sktyfuta  
@sktyfutb = sktyfutb  
end

def data\_comp  
@sktyfuta.merge(@sktyfutb) { |key, old\_value, new\_value| old\_value -  
new\_value }  
end  
#end  
end

class FinalNum  
attr\_reader :sktynl  
def initialize(sktynl)  
@sktynl = sktynl  
end

def numbers  
@nat = Hash.new(0)  
@sktynl.each do |key, value|  
key.to\_s  
if key \<= “739”  
key = “SKTY” # =\>  
@nat[key] += value  
elsif key \>=“740”  
key = “SKYNY” # =\>  
@nat[key] += value  
end  
end  
return @nat  
end  
end

Dir.chdir(“/Users/twolak”)  
post = SktyFut.new(“SKTYBal20080507.txt”)  
a = post.future\_data  
#a.sort!  
a.each{|key, value| puts “#{key} A value is #{value}”}  
pre = SktyFut.new(“SKTYBal20080506.txt”)  
b = pre.future\_data  
data = Calculate.new(a,b)  
iteration = data.data\_comp  
#iteration.sort  
#iteration.each{|key, value| puts “#{key} comp equals #{value}” }  
sktyfinal = FinalNum.new(iteration)  
cody = sktyfinal.numbers  
cody.each{ |key, value| puts “#{key} line is #{value}” }  
cody.to\_s

require ‘net/smtp’

Net::SMTP.start(‘[sktymx1.sktydev.com](http://sktymx1.sktydev.com)’, 25) do |smtp|  
smtp.open\_message\_stream(‘removed\_email\_address@domain.invalid’,  
[‘removed\_email\_address@domain.invalid’]) do |f|  
f.puts ‘From: removed\_email\_address@domain.invalid’  
f.puts ‘To: removed\_email\_address@domain.invalid’  
f.puts ‘Subject: test message’  
f.puts  
f.puts cody.each{ |key, value| puts “#{key} line is #{value}” }  
f.puts ‘This is a test message.’  
end  
end
