Il mio codice deve analizzare il formato Vcard 2.1. Sto usando vpim (non ci sono altre librerie)Vpim :: Vcard - Parsing vcard 2.1
Quando eseguo Vpim::Vcard.decode(data)
ottengo l'errore:
undefined method `each' for #<String:0x0000000928e778>
StackTrace:
NoMethodError (undefined method `each' for #<String:0x0000000928e778>):
vpim (0.695) lib/vpim/rfc2425.rb:82:in `unfold'
vpim (0.695) lib/vpim/rfc2425.rb:308:in `decode'
vpim (0.695) lib/vpim/vcard.rb:692:in `decode'
app/models/event.rb:71:in `block (2 levels) in parse_data'
Ho provato a correre gem install vcard
e require 'vCard 'directry (config.gem non include questo file dopo vpim gem) dopo l'inizializzazione di RailsApp. (config.gem 'vpim'
è incluso in environment.rb) In questo modo ottengo un altro errore:
;=D0=9D=D0=B0=D0=B4=D1=80=D0=B0=20=D0=B1=D0=B0=D0=BD=D0=BA=20=D0=BE=D0=BB=
(classe Exception è Vpim::InvalidEncodingError
) Codice
Vcard cerco parse:
BEGIN:VCARD
VERSION:2.1
REV:20090710T151929Z
TEL;CELL:80954130722
X-CLASS:private
END:VCARD
E 'interessante che secondo errore è quando sto decodifica all'interno di un modello di Rails. Quando provo a decodificare direttamente da script/console (dopo installinv vcard gem e direct includendo 'vcard') ho successo con l'oggetto Vcard.
StackTrace:
Vpim::InvalidEncodingError (;=D0=9D=D0=B0=D0=B4=D1=80=D0=B0=20=D0=B1=D0=B0=D0=BD=D0=BA=20=D0=BE=D0=BB=):
vcard (0.1.1) lib/vcard/field.rb:106:in `decode0'
vcard (0.1.1) lib/vcard/field.rb:172:in `initialize'
vcard (0.1.1) lib/vcard/field.rb:183:in `new'
vcard (0.1.1) lib/vcard/field.rb:183:in `decode'
vcard (0.1.1) lib/vcard/rfc2425.rb:308:in `block in decode'
vcard (0.1.1) lib/vcard/rfc2425.rb:308:in `collect'
vcard (0.1.1) lib/vcard/rfc2425.rb:308:in `decode'
vcard (0.1.1) lib/vcard/vcard.rb:686:in `decode'
app/models/event.rb:71:in `block (2 levels) in parse_data'
app/modelli/event.rb: 71:
vcard = Vpim::Vcard.decode(contact.text)
Ecco axample da IRB:
95-25-164-74:~ smix$ irb
ruby-1.9.2-rc2 > str = <<EOS
ruby-1.9.2-rc2"> BEGIN:VCARD
ruby-1.9.2-rc2"> VERSION:2.1
ruby-1.9.2-rc2"> REV:20090710T151929Z
ruby-1.9.2-rc2"> TEL;CELL:80954130722
ruby-1.9.2-rc2"> X-CLASS:private
ruby-1.9.2-rc2"> END:VCARD
ruby-1.9.2-rc2"> EOS
=> "BEGIN:VCARD\nVERSION:2.1\nREV:20090710T151929Z\nTEL;CELL:80954130722\nX-CLASS:private\nEND:VCARD\n"
ruby-1.9.2-rc2 > require 'vpim'
=> true
ruby-1.9.2-rc2 > Vpim::Vcard.decode str
NoMethodError: undefined method `each' for #<String:0x000001010e0428>
from /Users/smix/.rvm/gems/ruby-1.9.2-rc2/gems/vpim-0.695/lib/vpim/rfc2425.rb:82:in `unfold'
from /Users/smix/.rvm/gems/ruby-1.9.2-rc2/gems/vpim-0.695/lib/vpim/rfc2425.rb:308:in `decode'
from /Users/smix/.rvm/gems/ruby-1.9.2-rc2/gems/vpim-0.695/lib/vpim/vcard.rb:692:in `decode'
from (irb):10
from /Users/smix/.rvm/rubies/ruby-1.9.2-rc2/bin/irb:17:in `<main>'
ruby-1.9.2-rc2 >
Come è possibile analizzare Vcard 2.1 in rotaie?
potresti pubblicare più del tuo codice? hai provato a analizzare un oggetto io invece di una stringa? quale versione rubino stai usando? – elmac
puoi pubblicare lo stacktrace completo, per favore? –
Ho aggiornato la domanda. –