Module: Plist4r::Backend::Example
- Defined in:
- lib/plist4r/backend/example.rb
Class Methods
Overview
An example Plist4r Backend. These examples demonstrate the common convenience methods which are available to your backend. Its not necessary to implement all of the API methods in your backend. You may selectively implement any single method or method(s).
In the case of Example.from_string and Plist4r.open, the source plist format is not known beforehand. For those cases you should call Plist4r.string_detect_format or Plist4r.file_detect_format as appropriate. Then raise an exception for those situation where backend is unable to continue.
For example, if your backend is only able to load :xml files, then it should raise an exception whenever it encounters :binary or :gnustep formatted files. This is intentional. By throwing the error, it means the API call can be picked up and passed on to the next available backend.
Class Method Details
+ (Plist4r::Plist) from_binary(plist)
Parse a String of plist data and store it into the supplied Plist4r::Plist
- Please click “View Source” for the example.
41 42 43 44 45 46 47 |
# File 'lib/plist4r/backend/example.rb', line 41 def from_binary plist binary_string = plist.from_string hash = ::Plist4r::OrderedHash.new # import / convert plist data into ruby ordered hash plist.import_hash hash return plist end |
+ (Plist4r::Plist) from_gnustep(plist)
Parse a String of plist data and store it into the supplied Plist4r::Plist
- Please click “View Source” for the example.
55 56 57 58 59 60 61 |
# File 'lib/plist4r/backend/example.rb', line 55 def from_gnustep plist gnustep_string = plist.from_string hash = ::Plist4r::OrderedHash.new # import / convert plist data into ruby ordered hash plist.import_hash hash return plist end |
+ (Plist4r::Plist) from_xml(plist)
Parse a String of plist data and store it into the supplied Plist4r::Plist
- Please click “View Source” for the example.
27 28 29 30 31 32 33 |
# File 'lib/plist4r/backend/example.rb', line 27 def from_xml plist xml_string = plist.from_string hash = ::Plist4r::OrderedHash.new # import / convert plist data into ruby ordered hash plist.import_hash hash return plist end |
+ (String) to_binary(plist)
Convert a Plist4r::Plist into an “binary” formatted plist String
- Please click “View Source” for the example.
77 78 79 80 81 |
# File 'lib/plist4r/backend/example.rb', line 77 def to_binary plist hash = plist.to_hash binary_string = "Convert the plists's nested ruby hash into binary format here" return binary_string end |
+ (String) to_gnustep(plist)
Convert a Plist4r::Plist into a “gnustep” formatted plist String
- Please click “View Source” for the example.
87 88 89 90 91 |
# File 'lib/plist4r/backend/example.rb', line 87 def to_gnustep plist hash = plist.to_hash gnustep_string = "Convert the plists's nested ruby hash into gnustep format here" return gnustep_string end |
+ (String) to_xml(plist)
Convert a Plist4r::Plist into an “xml” formatted plist String
- Please click “View Source” for the example.
67 68 69 70 71 |
# File 'lib/plist4r/backend/example.rb', line 67 def to_xml plist hash = plist.to_hash xml_string = "Convert the plists's nested ruby hash into xml here" return xml_string end |