Class: MTP::Properties

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

Defined Under Namespace

Modules: Forms Classes: Property, PropertyDescription

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Properties

Returns a new instance of Properties.



3
4
5
# File 'lib/mtp/properties.rb', line 3

def initialize(object)
  @object = object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/mtp/properties.rb', line 39

def method_missing(method, *args)
  method = method.to_s
  if method[-1,1] == '='
    method.slice!(-1,1)
    set_value(method.camelize, *args).value
  else
    get_value(method.camelize, *args).value
  end
end

Instance Method Details

#clearObject



7
8
9
# File 'lib/mtp/properties.rb', line 7

def clear
  @supported = nil
end

#get_value(code) ⇒ Object



27
28
29
30
31
# File 'lib/mtp/properties.rb', line 27

def get_value(code)
  code = Property.code(code)
  raise UnsupportedProperty.new(@object, code)  unless supports?(code)
  Property.get(@object, code)
end

#set_value(code, value) ⇒ Object



33
34
35
36
37
# File 'lib/mtp/properties.rb', line 33

def set_value(code, value)
  code = Property.code(code)
  raise UnsupportedProperty.new(self, code) unless supports?(code)
  Property.set(@object, code, value)
end

#supportedObject



11
12
13
14
15
16
17
# File 'lib/mtp/properties.rb', line 11

def supported
  return @supported unless @supported.nil?
  
  t = @object.ph.transaction.get_object_props_supported(@object.format)
  t.expect("OK")
  @supported = t.data.payload.unpack("K+").first
end

#supports?(code) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/mtp/properties.rb', line 23

def supports?(code)
  supported.include?(code)
end

#writableObject



19
20
21
# File 'lib/mtp/properties.rb', line 19

def writable
  supported.select { |p| Property.description(@object, p).writable? }
end