Class: RubyQt6::QtCore::Private::MetaMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/qt6/qtcore/private/metamethod.rb

Constant Summary collapse

RE =
/(\w+ )?(\w+)\((.*)\)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature, type, underlying) ⇒ MetaMethod

Returns a new instance of MetaMethod.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/qt6/qtcore/private/metamethod.rb', line 32

def initialize(signature, type, underlying)
  matched = signature.match(RE)
  raise "Invalid metamethod signature: #{signature}" if matched.nil?

  @name = self.class.normalized_name(matched[2])
  @parameters = self.class.normalized_parameters(matched[3].split(","))
  @signature = self.class.normalized_signature(@name, @parameters)
  @return_type = self.class.normalized_return_type(matched[1])
  @type = type.to_sym
  @underlying = underlying.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/qt6/qtcore/private/metamethod.rb', line 9

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



10
11
12
# File 'lib/qt6/qtcore/private/metamethod.rb', line 10

def parameters
  @parameters
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



12
13
14
# File 'lib/qt6/qtcore/private/metamethod.rb', line 12

def return_type
  @return_type
end

#signatureObject (readonly)

Returns the value of attribute signature.



11
12
13
# File 'lib/qt6/qtcore/private/metamethod.rb', line 11

def signature
  @signature
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/qt6/qtcore/private/metamethod.rb', line 13

def type
  @type
end

Class Method Details

.normalized_name(name) ⇒ Object



15
16
17
# File 'lib/qt6/qtcore/private/metamethod.rb', line 15

def self.normalized_name(name)
  QtCore::Private.inflector.underscore(name)
end

.normalized_parameters(parameters) ⇒ Object



19
20
21
# File 'lib/qt6/qtcore/private/metamethod.rb', line 19

def self.normalized_parameters(parameters)
  parameters.map(&->(param) { param.delete(" ") })
end

.normalized_return_type(return_type) ⇒ Object



27
28
29
30
# File 'lib/qt6/qtcore/private/metamethod.rb', line 27

def self.normalized_return_type(return_type)
  return nil if return_type.nil?
  return_type.delete(" ")
end

.normalized_signature(normalized_name, normalized_parameters) ⇒ Object



23
24
25
# File 'lib/qt6/qtcore/private/metamethod.rb', line 23

def self.normalized_signature(normalized_name, normalized_parameters)
  normalized_name + "(" + normalized_parameters.join(",") + ")"
end

Instance Method Details

#qsignatureObject



52
53
54
55
# File 'lib/qt6/qtcore/private/metamethod.rb', line 52

def qsignature
  signature = self.class.normalized_signature(qsignature_name, @parameters)
  signal? ? "2#{signature}" : "1#{signature}"
end

#qsignature_nameObject



57
58
59
60
61
62
63
# File 'lib/qt6/qtcore/private/metamethod.rb', line 57

def qsignature_name
  case @underlying
  when :libQt6 then QtCore::Private.inflector.camelize(@name)
  when :ruby then "_rubyqt6_#{QtCore::Private.inflector.underscore(@name)}"
  else raise "Unknown underlying type: #{@underlying}"
  end
end

#signal?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/qt6/qtcore/private/metamethod.rb', line 44

def signal?
  @type == :signal
end

#slot?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/qt6/qtcore/private/metamethod.rb', line 48

def slot?
  @type == :slot
end