Top Level Namespace
Defined Under Namespace
Modules: ICalPal Classes: EventKit
Constant Summary collapse
- PL_CONVERT =
'/usr/bin/plutil -convert xml1 -o - -'.freeze
Instance Method Summary collapse
-
#ancestor ⇒ Integer
Get the application icalPal is most likely running in.
-
#plconvert(obj) ⇒ Array
Load a plist.
-
#xmlify(key, value) ⇒ String
Convert a key/value pair to XML.
Instance Method Details
#ancestor ⇒ Integer
Get the application icalPal is most likely running in
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/utils.rb', line 55 def ancestor ppid = Process.ppid while (ppid != 1) ps = `ps -p #{ppid} -o ppid,command | tail -1` ppid = ps[/^[0-9 ]+ /].to_i end ps[(ps.rindex('/') + 1)..].chop end |
#plconvert(obj) ⇒ Array
Load a plist
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/utils.rb', line 7 def plconvert(obj) r 'open3' r 'plist' # Run PL_CONVERT command sin, sout, _serr, _e = Open3.popen3(PL_CONVERT) # Send obj sin.write(obj) sin.close # Read output begin plist = Plist.parse_xml(sout.read) plist['$objects'] if plist rescue Plist::UnimplementedElementError nil end end |
#xmlify(key, value) ⇒ String
Convert a key/value pair to XML. The value should be nil, String, Integer, Array, or ICalPal::RDT
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/utils.rb', line 33 def xmlify(key, value) case value # Nil when NilClass then "<#{key}/>" # Array when Array # Treat empty arrays as nil values xmlify(key, nil) if value[0].nil? retval = '' value.each { |x| retval += xmlify("#{key}0", x) } "<#{key}>#{retval}</#{key}>" # Unknown else "<#{key}>#{value}</#{key}>" end end |