我的代码返回这个:"1.12.0.1058",我不确定我是否应该手动剥离"或什么。gsub没有剥离字符。
代码:response = RestClient.get(@deathburritoapp_url)
xml_doc = Nokogiri::XML(response)
@app_packages = xml_doc.xpath("//applicationPackages//applicationPackage")
if @app_packages != nil
@app_packages.each do |app_pack|
@package_id = app_pack.attribute("id").text.to_i
@version = app_pack.at_xpath("./version").text
@version = @version.gsub(/"\/, ' ')
@result = "Package Id: " + @package_id.inspect + "; Version: " + @version.inspect
Rails.logger.debug("Results: " + @result.inspect)
end
XML: <applicationPackages>
<applicationPackage id="229">
<application key="deathburrito" id="2">
<name>deathBURRITO</name>
</application>
<version>0.13.1 SNAPSHOT</version>
<packageType id="1">
<name>war</name>
</packageType>
<architecture id="5">
<name>java</name>
</architecture>
</applicationPackage>
<applicationPackage id="98">
<application key="deathburrito" id="2">
<name>deathBURRITO</name>
</application>
<version>1.10.0 SNAPSHOT</version>
<packageType id="1">
<name>war</name>
</packageType>
<architecture id="5">
<name>java</name>
</architecture>
</applicationPackage>
</applicationPackages>
调试结果:
Results: "Package Id: 229;版本:"0.13.1-SNAPSHOT "
这就是inspect
在做的事情:
ruby-1.9.2-p180 :002 > "foo".inspect
=> ""foo""
版本只是一个普通的ruby字符串,你不需要做任何特别的事情。