Class: MTP::Object
- Inherits:
-
Object
- Object
- MTP::Object
- Defined in:
- lib/mtp/object.rb
Constant Summary collapse
- PROTECTION_STATUS =
{ 0x0000 => "No protection", 0x0001 => "Read-only", 0x8002 => "Read-only Data", 0x8003 => "Non-transferable data"}
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
-
#compressed_size ⇒ Object
Returns the value of attribute compressed_size.
-
#data ⇒ Object
Returns the value of attribute data.
-
#date_created ⇒ Object
Returns the value of attribute date_created.
-
#date_modified ⇒ Object
Returns the value of attribute date_modified.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#format ⇒ Object
Returns the value of attribute format.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image_bit_depth ⇒ Object
readonly
Returns the value of attribute image_bit_depth.
-
#image_pix_height ⇒ Object
readonly
Returns the value of attribute image_pix_height.
-
#image_pix_with ⇒ Object
readonly
Returns the value of attribute image_pix_with.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#ph ⇒ Object
readonly
Returns the value of attribute ph.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#protection_status ⇒ Object
readonly
Returns the value of attribute protection_status.
-
#sequence_number ⇒ Object
readonly
Returns the value of attribute sequence_number.
-
#thumb_compressed_size ⇒ Object
readonly
Returns the value of attribute thumb_compressed_size.
-
#thumb_format ⇒ Object
readonly
Returns the value of attribute thumb_format.
-
#thumb_pix_height ⇒ Object
readonly
Returns the value of attribute thumb_pix_height.
-
#thumb_pix_width ⇒ Object
readonly
Returns the value of attribute thumb_pix_width.
Class Method Summary collapse
- .load(ph, id, storage = nil) ⇒ Object
- .property_accessor(*properties) ⇒ Object
- .property_reader(*properties) ⇒ Object
- .property_writer(*properties) ⇒ Object
- .register_format(klass, code) ⇒ Object
Instance Method Summary collapse
- #<=>(object) ⇒ Object
- #after_sending ⇒ Object
- #before_sending(ph) ⇒ Object
- #dump_properties ⇒ Object
-
#initialize ⇒ Object
constructor
A new instance of Object.
- #inspect ⇒ Object
- #load(ph, id, payload, storage = nil) ⇒ Object
- #new_object? ⇒ Boolean
- #pack ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Object
Returns a new instance of Object.
11 12 13 |
# File 'lib/mtp/object.rb', line 11 def initialize @properties = Properties.new(self) end |
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
7 8 9 |
# File 'lib/mtp/object.rb', line 7 def association @association end |
#compressed_size ⇒ Object
Returns the value of attribute compressed_size.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def compressed_size @compressed_size end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/mtp/object.rb', line 7 def data @data end |
#date_created ⇒ Object
Returns the value of attribute date_created.
7 8 9 |
# File 'lib/mtp/object.rb', line 7 def date_created @date_created end |
#date_modified ⇒ Object
Returns the value of attribute date_modified.
7 8 9 |
# File 'lib/mtp/object.rb', line 7 def date_modified @date_modified end |
#filename ⇒ Object
Returns the value of attribute filename.
7 8 9 |
# File 'lib/mtp/object.rb', line 7 def filename @filename end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def format @format end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def id @id end |
#image_bit_depth ⇒ Object (readonly)
Returns the value of attribute image_bit_depth.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def image_bit_depth @image_bit_depth end |
#image_pix_height ⇒ Object (readonly)
Returns the value of attribute image_pix_height.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def image_pix_height @image_pix_height end |
#image_pix_with ⇒ Object (readonly)
Returns the value of attribute image_pix_with.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def image_pix_with @image_pix_with end |
#keywords ⇒ Object
Returns the value of attribute keywords.
7 8 9 |
# File 'lib/mtp/object.rb', line 7 def keywords @keywords end |
#ph ⇒ Object (readonly)
Returns the value of attribute ph.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def ph @ph end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def properties @properties end |
#protection_status ⇒ Object (readonly)
Returns the value of attribute protection_status.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def protection_status @protection_status end |
#sequence_number ⇒ Object (readonly)
Returns the value of attribute sequence_number.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def sequence_number @sequence_number end |
#thumb_compressed_size ⇒ Object (readonly)
Returns the value of attribute thumb_compressed_size.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def thumb_compressed_size @thumb_compressed_size end |
#thumb_format ⇒ Object (readonly)
Returns the value of attribute thumb_format.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def thumb_format @thumb_format end |
#thumb_pix_height ⇒ Object (readonly)
Returns the value of attribute thumb_pix_height.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def thumb_pix_height @thumb_pix_height end |
#thumb_pix_width ⇒ Object (readonly)
Returns the value of attribute thumb_pix_width.
4 5 6 |
# File 'lib/mtp/object.rb', line 4 def thumb_pix_width @thumb_pix_width end |
Class Method Details
.load(ph, id, storage = nil) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/mtp/object.rb', line 46 def self.load(ph, id, storage = nil) object = nil t = ph.transaction.get_object_info(id) t.expect("OK") storage_id, format = t.data.payload.unpack("VK") object = @@format_classes[format.to_i].new object.load(ph, id, t.data.payload) end |
.property_accessor(*properties) ⇒ Object
35 36 37 38 |
# File 'lib/mtp/object.rb', line 35 def self.property_accessor(*properties) Object.property_reader(*properties) Object.property_writer(*properties) end |
.property_reader(*properties) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/mtp/object.rb', line 25 def self.property_reader(*properties) properties.each do |property| Object.class_eval %{ def #{property} properties.#{property} end } end end |
Instance Method Details
#<=>(object) ⇒ Object
114 115 116 |
# File 'lib/mtp/object.rb', line 114 def <=>(object) @id <=> object.id end |
#after_sending ⇒ Object
110 111 112 |
# File 'lib/mtp/object.rb', line 110 def after_sending @sent = true end |
#before_sending(ph) ⇒ Object
106 107 108 |
# File 'lib/mtp/object.rb', line 106 def before_sending(ph) @ph = ph end |
#dump_properties ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/mtp/object.rb', line 73 def dump_properties puts "0x%04x:%16s: %64s %s" % [ 0, "id", @id, "ro" ] properties.supported.each do |property| p = properties.get_value(property) puts "0x%04x:%16s: %64s %s" % [ p.code.to_i, property, p.value, (p.writable? ? 'rw' : 'ro') ] end end |
#inspect ⇒ Object
69 70 71 |
# File 'lib/mtp/object.rb', line 69 def inspect "#<MTP::Object:0x%08x @format=#{@format.name.inspect} @filename=#{@filename.inspect} @parent_id=0x%08x>" % [ @id, @parent_id ] end |
#load(ph, id, payload, storage = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mtp/object.rb', line 55 def load(ph, id, payload, storage = nil) @id = id @ph = ph @storage = storage @sent = true storage_id, @format, @protection_status, @compressed_size, @thumb_format, @thumb_compressed_size, @thumb_pix_width, @thumb_pix_height, @image_pix_width, @image_pix_height, @image_bit_depth, @parent_id, association_code, association_desc, @sequence_number, @filename, @date_created, @date_modified, @keywords = payload.unpack("VKSIKIIIIIIISIIJDDJ") @protection_status = Datacode.new(@protection_status, PROTECTION_STATUS) @association = Association.load(association_code, association_desc) self end |
#new_object? ⇒ Boolean
102 103 104 |
# File 'lib/mtp/object.rb', line 102 def new_object? !@sent end |
#pack ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/mtp/object.rb', line 94 def pack [ 0, @format, @protection_status || 0, @compressed_size || 0, @thumb_format || 0, # VKSIK @thumb_compressed_size || 0, @thumb_pix_width || 0, @thumb_pix_height || 0, #III @image_pix_width || 0, @image_pix_height || 0, @image_bit_depth || 0, #III @parent_id || 0, association.code, association.desc, @sequence_number || 0, #IKII @filename, @date_created, @date_modified, @keywords || "" ].pack("VKSIKIIIIIIIKIIJDDJ") end |
#valid? ⇒ Boolean
89 90 91 |
# File 'lib/mtp/object.rb', line 89 def valid? !@format.nil? and !@compressed_size.nil? end |