plist_lite 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81c314a0ff465217564b4040a14bfc7a8913e26d9be6b365c489f4117f07fd76
4
- data.tar.gz: 0ae9856ea9b8b13c691a4459ea907140d32d99cafedc6b726c570649a4ea77f3
3
+ metadata.gz: 185e2c46df646f8d59b7053b9085dea54e80e9120d4a8fa2ac5e7b8ca502aaa3
4
+ data.tar.gz: 574a799dcc799b5652d505a6f2b4c8dd16befd1b40ab6d95a5d92c7257126a7c
5
5
  SHA512:
6
- metadata.gz: c12c104cfd7c1daf21fc7813e7dacc6498ec14efce8e3950dafae565050ee6b6fa9488638a4fe9e254cdcfb4388776005ab22c6c3495ad8cc4e1f155212c3bc6
7
- data.tar.gz: 49ef1de68941d7683ec69843dc9a607ca97b85de8f9b2a7fbf299ffd66d2f965ce445593405c492ef54f3a2d7ed080888ac8eb8d6a6d7522702607a4b06400e8
6
+ metadata.gz: d8bed30ded79309cc7283a946e434e7b6628afbfa82697b0cd24a342de6d28aceb26f4e7a96b0f8b59d3ea46916e2d9da9d20e95d128b8ae4a16630872c27811
7
+ data.tar.gz: a53e5624eb7523095d2b00d08a550e4fd6d20913f69a9fc229bd74fbba9342d994649c41fca3f502c25d846e2bd3778b7b8f084f3952053b201c36943faa8ed1
data/lib/plist_lite.rb CHANGED
@@ -1,100 +1,2 @@
1
- # frozen_string_literal: true
2
-
3
- require 'nokogiri'
4
- require 'time'
5
- module PlistLite
6
- DTD = Dir.chdir(__dir__) do
7
- Nokogiri::XML::Document.parse(
8
- IO.read("#{__dir__}/minimal.plist"), nil, nil,
9
- Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::DTDLOAD)
10
- )
11
- end.external_subset
12
-
13
- class << self
14
- def load(source)
15
- doc = Nokogiri::XML::Document.parse(
16
- source, nil, nil,
17
- Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::STRICT)
18
- )
19
- raise doc.errors.first unless doc.errors.empty?
20
-
21
- errors = DTD.validate(doc)
22
- raise errors.first unless errors.empty?
23
-
24
- load_node(doc.root.elements.first)
25
- end
26
-
27
- def dump(obj)
28
- output = +'<?xml version="1.0" encoding="UTF-8"?>' \
29
- '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' \
30
- '<plist version="1.0">'
31
- dump_node(obj, output)
32
- output << '</plist>'
33
- end
34
-
35
- private
36
-
37
- def load_node(node)
38
- case node.name
39
- when 'dict'
40
- hash = {}
41
- node.elements.each_slice(2) do |key_node, value_node|
42
- hash[key_node.text] = load_node(value_node)
43
- end
44
- hash
45
- when 'array'
46
- array = []
47
- node.elements.each { |element| array << load_node(element) }
48
- array
49
- when 'integer' then node.text.to_i
50
- when 'real' then node.text.to_f
51
- when 'date' then Time.iso8601(node.text)
52
- when 'string' then node.text
53
- when 'data' then node.text.unpack1('m')
54
- when 'true' then true
55
- when 'false' then false
56
- end
57
- end
58
-
59
- def dump_node(obj, output)
60
- case obj
61
- when Hash
62
- output << '<dict>'
63
- obj.each do |key, value|
64
- case key
65
- when String then output << "<key>#{key.encode(xml: :text)}</key>"
66
- when Symbol then output << "<key>#{key}</key>"
67
- else
68
- raise TypeError, 'Hash key should be String or Symbol'
69
- end
70
- dump_node(value, output)
71
- end
72
- output << '</dict>'
73
- when Array
74
- output << '<array>'
75
- obj.each { |i| dump_node(i, output) }
76
- output << '</array>'
77
- when Symbol then output << "<string>#{obj}</string>"
78
- when String
79
- output <<
80
- case obj.encoding
81
- when Encoding::ASCII_8BIT then "<data>#{[obj].pack('m')}</data>"
82
- when Encoding::UTF_8 then "<string>#{obj.encode(xml: :text)}</string>"
83
- else "<string>#{obj.encode(Encoding::UTF_8, xml: :text)}</string>"
84
- end
85
- when Integer then output << "<integer>#{obj}</integer>"
86
- when Float then output << "<real>#{obj}</real>"
87
- when true then output << '<true/>'
88
- when false then output << '<false/>'
89
- when Time then output << "<date>#{Time.at(obj).utc.iso8601}</date>"
90
- when DateTime then output << "<date>#{obj.to_time.utc.iso8601}</date>"
91
- when Date
92
- warn 'Consider not using Date object because it does not contain time zone information'
93
- output << "<date>#{obj.iso8601}T00:00:00Z</date>"
94
- else raise ArgumentError, "unknown type: #{obj.class}"
95
- end
96
- end
97
- end
98
- end
99
-
100
- require 'plist_lite/ext'
1
+ require 'plist_lite/pure_ruby'
2
+ require 'plist_lite/ext' unless RUBY_PLATFORM == 'java'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plist_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weihang Jian
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-06-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: nokogiri
@@ -90,15 +89,11 @@ extra_rdoc_files: []
90
89
  files:
91
90
  - ext/plist_lite/ext/ext.c
92
91
  - ext/plist_lite/ext/extconf.rb
93
- - lib/minimal.plist
94
- - lib/plist.dtd
95
92
  - lib/plist_lite.rb
96
- - lib/plist_lite/ext.bundle
97
93
  homepage: https://github.com/tonytonyjan/plist_lite
98
94
  licenses:
99
95
  - MIT
100
96
  metadata: {}
101
- post_install_message:
102
97
  rdoc_options: []
103
98
  require_paths:
104
99
  - lib
@@ -113,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
108
  - !ruby/object:Gem::Version
114
109
  version: '0'
115
110
  requirements: []
116
- rubygems_version: 3.2.15
117
- signing_key:
111
+ rubygems_version: 3.6.9
118
112
  specification_version: 4
119
113
  summary: plist_lite is the fastest plist processor for Ruby written in C.
120
114
  test_files: []
data/lib/minimal.plist DELETED
@@ -1 +0,0 @@
1
- <?xml version="1.0"?><!DOCTYPE plist SYSTEM "plist.dtd"><_/>
data/lib/plist.dtd DELETED
@@ -1,19 +0,0 @@
1
- <!ENTITY % plistObject "(array | data | date | dict | real | integer | string | true | false )" >
2
- <!ELEMENT plist %plistObject;>
3
- <!ATTLIST plist version CDATA "1.0" >
4
-
5
- <!-- Collections -->
6
- <!ELEMENT array (%plistObject;)*>
7
- <!ELEMENT dict (key, %plistObject;)*>
8
- <!ELEMENT key (#PCDATA)>
9
-
10
- <!--- Primitive types -->
11
- <!ELEMENT string (#PCDATA)>
12
- <!ELEMENT data (#PCDATA)> <!-- Contents interpreted as Base-64 encoded -->
13
- <!ELEMENT date (#PCDATA)> <!-- Contents should conform to a subset of ISO 8601 (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'. Smaller units may be omitted with a loss of precision) -->
14
-
15
- <!-- Numerical primitives -->
16
- <!ELEMENT true EMPTY> <!-- Boolean constant true -->
17
- <!ELEMENT false EMPTY> <!-- Boolean constant false -->
18
- <!ELEMENT real (#PCDATA)> <!-- Contents should represent a floating point number matching ("+" | "-")? d+ ("."d*)? ("E" ("+" | "-") d+)? where d is a digit 0-9. -->
19
- <!ELEMENT integer (#PCDATA)> <!-- Contents should represent a (possibly signed) integer number in base 10 -->
Binary file