0

Hi I retrieved an Array from GMAIL API.

I want to record just the name of the receiver. I am pulling all sent emails into my app.

Here's the array that I retrieved:

[#<struct Net::IMAP::Address name="Shiela S", route=nil, mailbox="Shielas", host="test.com">]

I want to pass the receiver name into my Activity table . I already have the correct logic in passing values to my ActiveRecord but then how can I get just the name from the array above (dynamically).

I've tried to strip or split other unnecessary strings inside the array but no luck..

I want to end up having just the name which is Shiela S from the array above.

Any suggestions? Thanks

UPDATE

I've tried to convert to string and it worked!

In string:

"[#<struct Net::IMAP::Address name=\"Shiela S\", route=nil, mailbox=\"Shielas\", host=\"test.com\">]" 

Is there a better way than using slice! method to get the Shiela S substring?

Thanks

4

1 回答 1

1

您要访问的 Struct 包装在一个数组中,可能是因为一封电子邮件可以发送给多个收件人。所以,给定

recipients = [#<struct Net::IMAP::Address name="Shiela S", route=nil, mailbox="Shielas", host="test.com">]

你应该能够做到

recipients.first.name

获取第一个收件人的姓名,或

recipients.collect(&:name)

获取所有收件人姓名的数组。

于 2013-09-11T07:24:32.170 回答