summaryrefslogtreecommitdiff
path: root/lib/plist/parser.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plist/parser.rb')
-rw-r--r--lib/plist/parser.rb21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/plist/parser.rb b/lib/plist/parser.rb
index 7d1de9f..e0623ae 100644
--- a/lib/plist/parser.rb
+++ b/lib/plist/parser.rb
@@ -59,8 +59,15 @@ module Plist
end
class StreamParser
- def initialize( filename_or_xml, listener )
- @filename_or_xml = filename_or_xml
+ def initialize( plist_data_or_file, listener )
+ if plist_data_or_file.respond_to? :read
+ @xml = plist_data_or_file.read
+ elsif File.exists? plist_data_or_file
+ @xml = File.read( plist_data_or_file )
+ else
+ @xml = plist_data_or_file
+ end
+
@listener = listener
end
@@ -78,15 +85,7 @@ module Plist
require 'strscan'
- contents = (
- if (File.exists? @filename_or_xml)
- File.open(@filename_or_xml) {|f| f.read}
- else
- @filename_or_xml
- end
- )
-
- @scanner = StringScanner.new( contents )
+ @scanner = StringScanner.new( @xml )
until @scanner.eos?
if @scanner.scan(COMMENT_START)
@scanner.scan(COMMENT_END)