A
anne001
I have a soap4r created fx to search amazon which has too many
arguments to use comfortably
itemSearchRequest = ItemSearchRequest.new("", "", "", "", "", "", "",
"", "", "", "", "",
"","","","","","","gabin","","","","","","","","","","","","Books","","","","","")?
I would like to only type the name of the key search and the value. I
came up with some code which almost works. Can I do simpler, easier to
read than this? or more principled, more elegant?
------------------>
#Here is a simplified version of the fx, with just 2 elements
class ItemSearchRequest
attr_accessor :actor
attr_accessor :artist
def initialize(actor = nil, artist = nil)
@actor = actor
@artist = artist
end
end
itemSearchRequest = ItemSearchRequest.new
p itemSearchRequest.inspect
itemSearchRequest = ItemSearchRequest.new("", "dud")
p itemSearchRequest.inspect
itemSearchRequest = ItemSearchRequest.new(artist="dod")
p itemSearchRequest.inspect
-------->
# this is the method I wrote to simplify the accessing of the fx
def namedrequest(fxname,hash)
nameinfo=eval(fxname).new.inspect
p nameinfo
# should return something like the following
# nameinfo="#<ItemSearchRequest:0x25cd4 @artist=nil, @actor=nil>"
command=fxname.slice(0,1).downcase+fxname.slice(1,fxname.length)+"="+fxname+".new("
namearray=nameinfo.scan(/@(\w+)=/)
namearray.each{ |key|
p key
p key[0]
command = command +'"'+ (hash[key[0]] || "")+'",'
}
#replace last coma with )
command = command.sub(/,$/,")")
p command
eval(command)
end
namedrequest("ItemSearchRequest",{"artist" =>"dod", "actor" =>"dud"})
p itemSearchRequest
arguments to use comfortably
itemSearchRequest = ItemSearchRequest.new("", "", "", "", "", "", "",
"", "", "", "", "",
"","","","","","","gabin","","","","","","","","","","","","Books","","","","","")?
I would like to only type the name of the key search and the value. I
came up with some code which almost works. Can I do simpler, easier to
read than this? or more principled, more elegant?
------------------>
#Here is a simplified version of the fx, with just 2 elements
class ItemSearchRequest
attr_accessor :actor
attr_accessor :artist
def initialize(actor = nil, artist = nil)
@actor = actor
@artist = artist
end
end
itemSearchRequest = ItemSearchRequest.new
p itemSearchRequest.inspect
itemSearchRequest = ItemSearchRequest.new("", "dud")
p itemSearchRequest.inspect
itemSearchRequest = ItemSearchRequest.new(artist="dod")
p itemSearchRequest.inspect
-------->
# this is the method I wrote to simplify the accessing of the fx
def namedrequest(fxname,hash)
nameinfo=eval(fxname).new.inspect
p nameinfo
# should return something like the following
# nameinfo="#<ItemSearchRequest:0x25cd4 @artist=nil, @actor=nil>"
command=fxname.slice(0,1).downcase+fxname.slice(1,fxname.length)+"="+fxname+".new("
namearray=nameinfo.scan(/@(\w+)=/)
namearray.each{ |key|
p key
p key[0]
command = command +'"'+ (hash[key[0]] || "")+'",'
}
#replace last coma with )
command = command.sub(/,$/,")")
p command
eval(command)
end
namedrequest("ItemSearchRequest",{"artist" =>"dod", "actor" =>"dud"})
p itemSearchRequest