hi again, can i ask something bout the method and class thing?
i have a class called map.rb, and another class called Asset.rb
in my Asset.rb, i have a method called
def base_part_of(file_name)
name = File.basename(file_name)
name.gsub(/[^W._-]/, '''')
sanitize_filename(name)
end
so, wat can i do in order to get the "name" from base_part_of in my
map
class?
isit i use require ''Asset'', or
isit i create a string called ''try''
then try = name or something?
thx for helping again...
cheers~~
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 4 Jun 2008, at 06:01, loki ja wrote:> > hi again, can i ask something bout the method and class thing? > > i have a class called map.rb, and another class called Asset.rb > > in my Asset.rb, i have a method called > > def base_part_of(file_name) > name = File.basename(file_name) > name.gsub(/[^W._-]/, '''') > sanitize_filename(name) > end > > so, wat can i do in order to get the "name" from base_part_of in my > map > class? >What you''ve got there is an instance method of the Asset class. You can''t (without black magic) pull an instance method out of a class and use it on it''s own. So either you''ve got an instance of asser and you can call some_asset.base_part_of(...) or you make that method class method (which seems reasonable enough in this case) by defining it as self.base_part_of and then calling it as Asset.base_part_of(...). You would also have to make sanitize_filename a class method as well. Fred> > isit i use require ''Asset'', or > > isit i create a string called ''try'' > then try = name or something? > > thx for helping again... > > cheers~~ > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
okok, thx for the tips, i''ll try out and i''ll ask again~~ hehe -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hey fred, would u mind if u help me check the error, in my .... program, cause im now at my last part , which is i need to load a random file which ends with .lmx, isit ok if u help me check? cause after the tips u gave me i think my whole thing is like... screwed .... >.< -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 4, 8:09 am, loki ja <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hey fred, would u mind if u help me check the error, in my .... > program, > > cause im now at my last part , which is i need to load a random file > which ends with .lmx, isit ok if u help me check? cause after the tips u > gave me i think my whole thing is like... screwed .... >.< >If you post some more of your code I''m sure someone would be able to help. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ow... but its a whole chunks of things......
or how am i read a file name? jus the file name with the extension .lmx
a = File.open("C:/rubydev/prac1/mail6/log/new_file_name.lmx" )
puts a
doc = Document.new File.new("C:/rubydev/prac1/mail6/log/River_Va.lmx")
this is what i have, ive tried to use file.open, but it shows me weird
numbers...
#<File:0x3799854>
but actually i wanna read those file with extension .lmx, is there a
way?
cause after reading it, i wanna put inside my doc
...
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 4 Jun 2008, at 09:56, loki ja wrote:> > ow... but its a whole chunks of things...... > > or how am i read a file name? jus the file name with the > extension .lmx > > a = File.open("C:/rubydev/prac1/mail6/log/new_file_name.lmx" ) >File.basename does that> puts a > > doc = Document.new File.new("C:/rubydev/prac1/mail6/log/River_Va.lmx") > > > this is what i have, ive tried to use file.open, but it shows me weird > numbers... > > #<File:0x3799854>That''s a file object. Use read/readline/readlines to read from it. Fred> > > but actually i wanna read those file with extension .lmx, is there a > way? > > cause after reading it, i wanna put inside my doc > > ... > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
alright, im still stuck, erm, this is my code...
First, this is my action mailer, which read and create file from the
email, it will auto generates the file after reading the email and save
it somewhere
require ''ActionMailer''
class AssetSubmitHandler < ActionMailer::Base
# content type should be validated to image/gif, image/jpg, or
image/jpeg
def receive(email)
if email.has_attachments?
email.attachments.each do |attachment|
# save original file
File.open("C:/rubydev/prac1/mail6/log/" +
base_part_of(attachment.original_filename),File::CREAT|File::TRUNC|File::WRONLY,0666){
|f|
f.write(attachment.read)
f.close()
}
end
end
end
def base_part_of(file_name)
name = File.basename(file_name)
name.gsub(/[^W._-]/, '''')
sanitize_filename(name)
end
# Fixes a ''feature'' of IE where it passes the entire path
instead of
just the filename
def sanitize_filename(value)
#get only the filename (not the whole path)
just_filename = value.gsub(/^.*(\\|\/)/, '''')
just_filename.gsub(/[^\w\.\-]/,''_'')
end
end
then, at my map class, i need to read the file and process the lmx file
and save to database.
require ''ActiveRecord''
class Map
require ''rexml/document''
require "mysql"
require "dbi"
include REXML
require ''AssetSubmitHandler''
#~ scanfile = File.new("C:/rubydev/prac1/mail6/log/River_Va.lmx")
#~ dbname="email_development"
#~ doc = REXML::Document.new scanfile
a = File.open("C:/rubydev/prac1/mail6/log/new_file_name.lmx" )
puts a
doc = Document.new File.new("C:/rubydev/prac1/mail6/log/River_Va.lmx")
#~ doc.elements.each("lm:landmarkCollection") { |element| puts
element.attributes["lm:latitude"]
#~ latitude = element.attributes["lm:latitude"]
#~ }
#~ root = doc.root
#~ puts
root.elements["lm:lmx/lm:landmarkCollection/lm:landmark/lm:coordinates"].attributes["lm:latitude"]
names = []
invisibility = XPath.first( doc, "//lm:landmark" )
XPath.each( doc, "//lm:name") { |element| puts names <<
element.text}
XPath.match( doc, "//lm:name" )
puts names
latitude = []
invisibility = XPath.first( doc, "/*/lm:landmark" )
XPath.each( doc, "//lm:latitude") { |element| puts latitude <<
element.text}
XPath.match( doc, "//lm:latitude" )
puts latitude
longitude = []
invisibility = XPath.first( doc, "/*/lm:landmark" )
XPath.each( doc, "//lm:longitude") { |element| puts longitude <<
element.text}
XPath.match( doc, "//lm:longitude" )
puts longitude
# db insert
m = Mysql.new("localhost", "root", "",
"email_development")
sth=m.query("insert into maps (name,latitude,longtitude) values
(''#{names}'',''#{latitude}'',''#{longitude}'')")
end
Now, the problem i faced is, how am i going to read the file was
generated from action mailer, by using file.new, file.basename, or file
open?
or is there a better way to get the file generated from action mailer?
thx for helping me again~~
cheers~~
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Jun 5, 2:27 am, loki ja <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Now, the problem i faced is, how am i going to read the file was > generated from action mailer, by using file.new, file.basename, or file > open?Well somehow you''ve got to figure out where the file is. So either you store that in the database at the point at which you process the message, or perhaps it''s enough for you to just process all files in that folger, in which case Dir.glob should do the trick. On top of that your sql query won''t work (single quotes aren''t interpolated, and it wouldn''t be valid syntax anyway. It''s also quite hard to read your code because there are so many lines there which do nothing. Fred> > or is there a better way to get the file generated from action mailer? > thx for helping me again~~ > > cheers~~ > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---