Class: RXCode::Archive
- Inherits:
-
Object
- Object
- RXCode::Archive
- Defined in:
- lib/rxcode/models/archive.rb
Overview
Processes an NSKeyedArchive file into a set of Ruby objects
Instance Attribute Summary collapse
-
#archive_hash ⇒ Object
readonly
Returns the value of attribute archive_hash.
-
#archive_path ⇒ Object
readonly
ARCHIVE PATH ===============================================================================================.
-
#object_mapper ⇒ Object
Returns the value of attribute object_mapper.
Class Method Summary collapse
- .archive_at_path(archive_path) ⇒ Object
-
.object_at_path(archive_path) ⇒ Object
Returns the object archived in the file identified by
archive_path
.
Instance Method Summary collapse
-
#initialize(archive_path_or_hash, &object_mapper) ⇒ Archive
constructor
A new instance of Archive.
- #model_object_with_id(object_id) ⇒ Object
- #object_hashes ⇒ Object
-
#object_with_id(object_id) ⇒ Object
OBJECTS ====================================================================================================.
- #root_object ⇒ Object
-
#root_object_archive_id ⇒ Object
ROOT OBJECT ================================================================================================.
Constructor Details
#initialize(archive_path_or_hash, &object_mapper) ⇒ Archive
Returns a new instance of Archive.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rxcode/models/archive.rb', line 8 def initialize(archive_path_or_hash, &object_mapper) if archive_path_or_hash.is_a?(String) if File.exist?(archive_path_or_hash) @archive_path = archive_path_or_hash @archive_hash = Plist::parse_xml(`plutil -convert xml1 -o - '#{archive_path_or_hash}'`) else @archive_hash = Plist::parse_xml(archive_path_or_hash) end elsif archive_path_or_hash.is_a?(Hash) @archive_hash = archive_path_or_hash end @objects = {} @object_mapper = object_mapper end |
Instance Attribute Details
#archive_hash ⇒ Object (readonly)
Returns the value of attribute archive_hash.
32 33 34 |
# File 'lib/rxcode/models/archive.rb', line 32 def archive_hash @archive_hash end |
#archive_path ⇒ Object (readonly)
ARCHIVE PATH ===============================================================================================
30 31 32 |
# File 'lib/rxcode/models/archive.rb', line 30 def archive_path @archive_path end |
#object_mapper ⇒ Object
Returns the value of attribute object_mapper.
34 35 36 |
# File 'lib/rxcode/models/archive.rb', line 34 def object_mapper @object_mapper end |
Class Method Details
.archive_at_path(archive_path) ⇒ Object
65 66 67 |
# File 'lib/rxcode/models/archive.rb', line 65 def self.archive_at_path(archive_path) self.new(archive_path) end |
.object_at_path(archive_path) ⇒ Object
Returns the object archived in the file identified by archive_path
.
72 73 74 |
# File 'lib/rxcode/models/archive.rb', line 72 def self.object_at_path(archive_path) archive_at_path(archive_path).root_object end |
Instance Method Details
#model_object_with_id(object_id) ⇒ Object
55 56 57 58 59 |
# File 'lib/rxcode/models/archive.rb', line 55 def model_object_with_id(object_id) if o = object_with_id(object_id) o.model_object end end |
#object_hashes ⇒ Object
61 62 63 |
# File 'lib/rxcode/models/archive.rb', line 61 def object_hashes archive_hash['objects'] end |
#object_with_id(object_id) ⇒ Object
OBJECTS ====================================================================================================
48 49 50 51 52 53 |
# File 'lib/rxcode/models/archive.rb', line 48 def object_with_id(object_id) @objects[object_id] ||= if object_hashes[object_id] ArchivedObject.new(self, object_id) end end |
#root_object ⇒ Object
42 43 44 |
# File 'lib/rxcode/models/archive.rb', line 42 def root_object object_with_id(root_object_archive_id) end |
#root_object_archive_id ⇒ Object
ROOT OBJECT ================================================================================================
38 39 40 |
# File 'lib/rxcode/models/archive.rb', line 38 def root_object_archive_id @archive_hash['rootObject'] end |