Git Product home page Git Product logo

cfplist's Introduction

CFPlist

Native bindings for CoreFoundation Property List files in ruby.

Note this this gem will only work on platforms where the CoreFoundation.framework is present, which means macOS.

Installation

Add this line to your application's Gemfile:

gem 'cfplist'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install cfplist

Usage

To load a property list from a string, do this:

require "cfplist"

data = File.read("/path/to/whatever.plist")
plist = CFPlist.parse(data)

This will return either an Array or a Hash, depending on the structure of the property list.

To generate a property list from an an Array or Hash, do this:

require "cfplist"

my_hash = { "foo" => "bar", "baz" => "quux" }
data = CFPlist.generate(my_hash)  # => data is a string containing the generated plist

File.open("/path/to/whatever.plist", "r") do |io|
  io.write(data)
end

The following methods are also implemented for compatibility with the json gem and the Marshal API:

  • .[](object, opts = {})

    • If object is string-like, parse the string and return the parsed result as a ruby data structure. Otherwise, generate Property List text from the Ruby data structure and return it.
  • .dump(object, an_io = nil, limit = nil)

    • Dumps obj as a Property List string, i.e. calls .generate on the object and returns the result.
    • If an_io (an IO-like object or an object that responds to the #write) method was given, the resulting Property List is written to it.
    • If the number of nested arrays or objects exceeds limit, an ArgumentError exception is raised. This argument is similar (but not exactly the same!) to the limit argument in Marshal.dump.
  • .load(source, proc = nil, options = {})

    • Load a ruby data structure from a Property List source and return it. A source can either be a string-like object, an IO-like object, or an object responding to the read method. If proc was given, it will be called with any nested Ruby object as an argument recursively in depth first order.
    • BEWARE: This method is meant to serialise data from trusted user input, like from your own database server or clients under your control, it could be dangerous to allow untrusted users to pass JSON sources into it.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/baberthal/cfplist. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Cfplist project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

cfplist's People

Contributors

baberthal avatar

Watchers

James Cloos 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.