Class: MTP::Properties::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/mtp/properties.rb

Constant Summary collapse

@@descriptions =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



52
53
54
# File 'lib/mtp/properties.rb', line 52

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



52
53
54
# File 'lib/mtp/properties.rb', line 52

def description
  @description
end

#valueObject (readonly)

Returns the value of attribute value.



52
53
54
# File 'lib/mtp/properties.rb', line 52

def value
  @value
end

Class Method Details

.code(code) ⇒ Object



59
60
61
# File 'lib/mtp/properties.rb', line 59

def self.code(code)
  (code.is_a?(Datacode) ? code : Datacode.new(code, nil, MTP::Datacode::Masks::OBJECT_PROPERTY))
end

.description(object, code) ⇒ Object



54
55
56
57
# File 'lib/mtp/properties.rb', line 54

def self.description(object, code)
  raise UnsupportedProperty.new(object, code) unless object.properties.supports?(code)
  @@descriptions[code.to_i] ||= PropertyDescription.load(object.ph, code, object.format)
end

.get(object, c) ⇒ Object

Raises:



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mtp/properties.rb', line 63

def self.get(object, c)
  raise MTPError.new("object is not stored on the device") if object.new_object?
  prop = Property.new
  prop.instance_eval do
    @object = object
    @code = Property.code(c)
    @description = Property.description(object, @code)
    t = object.ph.transaction.get_object_prop_value(object.id, @code)
    t.expect("OK")
    @value = @description.unpack(t.data.payload)
  end
  prop
end

.set(object, c, value) ⇒ Object

Raises:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/mtp/properties.rb', line 77

def self.set(object, c, value)
  raise MTPError.new("object is not stored on the device") if object.new_object?
  prop = Property.new
  prop.instance_eval do
    @object = object
    @code = Property.code(c)
    @description = Property.description(object, @code)
    t = object.ph.transaction
    t.data = Data.new(@description.pack(value))
    t.set_object_prop_value(object.id, @code)
    t.expect("OK")
    @value = value
  end
  prop
end

Instance Method Details

#writable?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/mtp/properties.rb', line 93

def writable?
  Property.description(@object, @code).writable?
end