Giter VIP home page Giter VIP logo

nokogiri-plist's Introduction

Nokogiri-PList

DESCRIPTION:

Nokogiri-plist provides the functionality for dealing with XML in Apple’s property list format.

There is already a plist gem (github.com/bleything/plist) that has similar functionality. I didn’t realize it until I had written most of this gem. However this gem uses Nokogiri, so the implementation is simpler. The plist gem does its own XML parsing. I figured since I was already using Nokogiri in my project, it’s better to build on top of that. I did get ideas from the original gem. I have benchmarked my gem against that gem and it performs similarly. Once I come up with a little more scientific benchmarks, I’ll show them.‘

FEATURES:

  • Parsers plist files into simple basic Ruby objects

  • Generates plist XML from Ruby objects

  • Uses the awesome Nokogiri gem

USAGE:

Sample plist (test.plist)

<plist>
  <dict>
    <key>Beers</key>
    <array>
      <string>Black Butte</string>
      <string>Steel Reserve</string>
      <string>Bass Pale Ale</string>
    </array>
    <key>Beer Drinker</key><string>Casey</key>
    <key>Beers Drank</key><integer>4123</integer>
  </dict>
</plist>

>  require 'nokogiri-plist'

Parse the plist XML

>  plist = Nokogiri::PList(open('test.plist'))
=> { "Beers" => ["Black Butte", "Steel Reserve", "Bass Pale Ale"], "Beers Drank" => 4123, "Beer Drinker" => "Casey"}

Read a dict property thats value is an array

>  plist["Beers"]
=> ["Black Butte", "Steel Reserve", "Bass Pale Ale"]

Read another value

>  plist["Beer Drinker"]
=> "Casey"

Turn it into a string containing XML

> puts plist.to_plist_xml
  <dict>
    <key>Beers</key>
    <array>
      <string>Black Butte</string>
      <string>Steel Reserve</string>
      <string>Bass Pale Ale</string>
    </array>
    <key>Beers Drank</key><integer>4123</integer>
    <key>Beer Drinker</key><string>Casey</string>
  </dict>

Convert a string into a plist XML string

> "beer".to_plist_xml
=> "<string>beer</string>" 

Convert an array to a plist XML string

> puts (1..3).to_a.to_plist_xml
<array>
  <integer>1</integer>
  <integer>2</integer>
  <integer>3</integer>
</array>

REQUIREMENTS:

  • Ruby (tested with 1.9.1 and 1.8.7)

  • nokogiri

  • shoulda and mocha (only if you want to run the tests)

INSTALL:

  • sudo

    gem install nokogiri-plist

nokogiri-plist's People

Contributors

caseyhoward avatar

Watchers

Ari Braginsky avatar Skye avatar John Kellar avatar Ivan Stroganov avatar James Cloos avatar Yuting avatar  avatar Fish avatar  avatar Rick Donald avatar  avatar  avatar  avatar Medhelp Jenkins avatar  avatar  avatar  avatar Ari Braginsky avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.