Class: MooTool::Models::FileLocation
- Inherits:
-
Object
- Object
- MooTool::Models::FileLocation
- Defined in:
- lib/mootool/models/file_location.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#hashes ⇒ Object
Returns the value of attribute hashes.
-
#location ⇒ Object
Returns the value of attribute location.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
- #fullname ⇒ Object
- #has_hash? ⇒ Boolean
- #hash?(hash) ⇒ Boolean
- #hashes_from_build_identity(path) ⇒ Object
- #img4? ⇒ Boolean
-
#initialize(location, filename, hashes = nil) ⇒ FileLocation
constructor
A new instance of FileLocation.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_json(*options) ⇒ Object
- #to_ref(_hash) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(location, filename, hashes = nil) ⇒ FileLocation
Returns a new instance of FileLocation.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mootool/models/file_location.rb', line 8 def initialize(location, filename, hashes = nil) @location = location @filename = filename case hashes when MooTool::Models::Digest @hashes = [hashes] when String [MooTool::Models::Digest.create(hashes)] when Array @hashes = hashes.map { |h| MooTool::Models::Digest.create(h) } end end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/mootool/models/file_location.rb', line 6 def filename @filename end |
#hashes ⇒ Object
Returns the value of attribute hashes.
6 7 8 |
# File 'lib/mootool/models/file_location.rb', line 6 def hashes @hashes end |
#location ⇒ Object
Returns the value of attribute location.
6 7 8 |
# File 'lib/mootool/models/file_location.rb', line 6 def location @location end |
Class Method Details
.from_hash(hash) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/mootool/models/file_location.rb', line 88 def self.from_hash(hash) if hash.key? 'hashes' new hash['location'], hash['filename'], hash['hashes'] else new hash['location'], hash['filename'] end end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
72 73 74 |
# File 'lib/mootool/models/file_location.rb', line 72 def as_json( = {}) to_h end |
#fullname ⇒ Object
25 26 27 |
# File 'lib/mootool/models/file_location.rb', line 25 def fullname File.join(@location, @filename) end |
#has_hash? ⇒ Boolean
21 22 23 |
# File 'lib/mootool/models/file_location.rb', line 21 def has_hash? @hashes&.any? end |
#hash?(hash) ⇒ Boolean
67 68 69 70 |
# File 'lib/mootool/models/file_location.rb', line 67 def hash?(hash) hash = MooTool::Models::Digest.create(hash) unless hash.is_a?(MooTool::Models::Digest) @hashes.any? { |h| h == hash } end |
#hashes_from_build_identity(path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mootool/models/file_location.rb', line 29 def hashes_from_build_identity(path) parsed = CFPropertyList.native_types(CFPropertyList::List.new(file: path).value).deep_symbolize_keys results = parsed[:BuildIdentities].flat_map do |identity| identity[:Manifest].map do |_key, value| value[:Digest] end end results.uniq.map { |h| Models::Digest.create(h) } end |
#img4? ⇒ Boolean
58 59 60 61 62 63 64 65 |
# File 'lib/mootool/models/file_location.rb', line 58 def img4? case fullname when /\.img4$/, /\.im4m$/, /\.im4p$/, /apticket.*\.der/, /com\.apple\.factorydata/ true else false end end |
#inspect ⇒ Object
84 85 86 |
# File 'lib/mootool/models/file_location.rb', line 84 def inspect to_h.ai end |
#to_h ⇒ Object
50 51 52 |
# File 'lib/mootool/models/file_location.rb', line 50 def to_h { path: fullname, location: @location, filename: @filename, hashes: @hashes } end |
#to_json(*options) ⇒ Object
76 77 78 |
# File 'lib/mootool/models/file_location.rb', line 76 def to_json(*) as_json(*).to_json(*) end |
#to_ref(_hash) ⇒ Object
80 81 82 |
# File 'lib/mootool/models/file_location.rb', line 80 def to_ref(_hash) fullname.to_s end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/mootool/models/file_location.rb', line 54 def to_s fullname end |