Class: Babushka::XMLString
Instance Method Summary collapse
-
#val_for(key) ⇒ Object
This extracts values from XML, like that found in .plist files.
Methods inherited from String
#/, #blank?, #colorize, #colorize!, #colorized?, #decolorize, #decolorize!, #end_with, #ends_with?, #start_with, #starts_with?, #to_version, #with, #xml_val_for
Methods included from Fancypath::Helpers
#to_expanded_fancypath, #to_fancypath, #to_tilde_expanded_path
Instance Method Details
#val_for(key) ⇒ Object
This extracts values from XML, like that found in .plist files. For example,
%Q{
<key>SVNPath</key>
<string>/trunk/src</string>
<key>SVNRevision</key>
<string>37609</string>
}.val_for('SVNRevision') #=> "37609"
It doesn’t work for arrays, and probably doesn’t work for boolean values. Patches welcome :)
14 15 16 17 18 19 20 |
# File 'lib/babushka/xml_string.rb', line 14 def val_for key split(/<\/[^>]+>\n\s*<key>/m).select {|i| i[/#{Regexp.escape(key)}<\/key>/] }.map {|i| i.scan(/<[^\/>]+>(.*)$/m) }.flatten.first end |