开发者

Not sure I am using Nokogiri in Ruby correctly

My code returns this: \"1.12.0.1058\" and I am not sure if I should be stripping out the \" manually or what. The gsub is not stripping the characters out.

Code:

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 f开发者_C百科rom Debug:

Results: "Package Id: 229; Version: \"0.13.1-SNAPSHOT\""


That's just inspect doing it's thing:

ruby-1.9.2-p180 :002 > "foo".inspect
 => "\"foo\"" 

The version is just a normal ruby string, you don't need to do anything special.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜