Module: KRPC::Attributes
- Defined in:
- lib/krpc/attributes.rb
Class Method Summary collapse
- .get_class_method_or_property_name(attrs) ⇒ Object
- .get_class_name(attrs) ⇒ Object
- .get_parameter_type_attrs(pos, attrs) ⇒ Object
- .get_property_name(attrs) ⇒ Object
- .get_return_type_attrs(attrs) ⇒ Object
- .get_service_name(attrs) ⇒ Object
- .is_a_class_method(attrs) ⇒ Object
- .is_a_class_method_or_property_accessor(attrs) ⇒ Object
- .is_a_class_property_accessor(attrs) ⇒ Object
- .is_a_class_property_getter(attrs) ⇒ Object
- .is_a_class_property_setter(attrs) ⇒ Object
- .is_a_class_static_method(attrs) ⇒ Object
- .is_a_property_accessor(attrs) ⇒ Object
- .is_a_property_getter(attrs) ⇒ Object
- .is_a_property_setter(attrs) ⇒ Object
- .is_any_start_with?(attrs, prefix) ⇒ Boolean (also: asw?)
Class Method Details
.get_class_method_or_property_name(attrs) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/krpc/attributes.rb', line 57 def get_class_method_or_property_name(attrs) if is_a_class_method(attrs) || is_a_class_static_method(attrs) || is_a_class_property_accessor(attrs) attrs.each do |a| return $1 if /^Class\.(?:(?:Static)?Method|Property\.(?:Get|Set))\([^,]+,([^,]+)\)$/ =~ a end end raise(ValueError, "Procedure attributes are not a class method or class property accessor") end |
.get_class_name(attrs) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/krpc/attributes.rb', line 35 def get_class_name(attrs) if is_a_class_method(attrs) || is_a_class_static_method(attrs) attrs.each do |a| return $1 if /^Class\.(?:Static)?Method\([^,\.]+\.([^,\.]+),[^,]+\)$/ =~ a end elsif is_a_class_property_accessor(attrs) attrs.each do |a| return $1 if /^Class\.Property.(?:Get|Set)\([^,\.]+\.([^,]+),[^,]+\)$/ =~ a end end raise(ValueError, "Procedure attributes are not a class method or property accessor") end |
.get_parameter_type_attrs(pos, attrs) ⇒ Object
66 67 68 69 70 |
# File 'lib/krpc/attributes.rb', line 66 def get_parameter_type_attrs(pos, attrs) attrs.map do |a| (/^ParameterType\(#{pos}\).(.+)$/ =~ a) ? $1 : nil end.compact end |
.get_property_name(attrs) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/krpc/attributes.rb', line 48 def get_property_name(attrs) if is_a_property_accessor(attrs) attrs.each do |a| return $1 if /^Property\.(?:Get|Set)\((.+)\)$/ =~ a end end raise(ValueError, "Procedure attributes are not a property accessor") end |
.get_return_type_attrs(attrs) ⇒ Object
72 73 74 75 76 |
# File 'lib/krpc/attributes.rb', line 72 def get_return_type_attrs(attrs) attrs.map do |a| (/^ReturnType.(.+)$/ =~ a) ? $1 : nil end.compact end |
.get_service_name(attrs) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/krpc/attributes.rb', line 22 def get_service_name(attrs) if is_a_class_method(attrs) || is_a_class_static_method(attrs) attrs.each do |a| return $1 if /^Class\.(?:Static)?Method\(([^,\.]+)\.[^,]+,[^,]+\)$/ =~ a end elsif is_a_class_property_accessor(attrs) attrs.each do |a| return $1 if /^Class\.Property.(?:Get|Set)\(([^,\.]+)\.[^,]+,[^,]+\)$/ =~ a end end raise(ValueError, "Procedure attributes are not a class method or property accessor") end |
.is_a_class_method(attrs) ⇒ Object
16 |
# File 'lib/krpc/attributes.rb', line 16 def is_a_class_method(attrs) asw?(attrs,"Class.Method(") end |
.is_a_class_method_or_property_accessor(attrs) ⇒ Object
15 |
# File 'lib/krpc/attributes.rb', line 15 def is_a_class_method_or_property_accessor(attrs) asw?(attrs,"Class.") end |
.is_a_class_property_accessor(attrs) ⇒ Object
18 |
# File 'lib/krpc/attributes.rb', line 18 def is_a_class_property_accessor(attrs) asw?(attrs,"Class.Property.") end |
.is_a_class_property_getter(attrs) ⇒ Object
19 |
# File 'lib/krpc/attributes.rb', line 19 def is_a_class_property_getter(attrs) asw?(attrs,"Class.Property.Get(") end |
.is_a_class_property_setter(attrs) ⇒ Object
20 |
# File 'lib/krpc/attributes.rb', line 20 def is_a_class_property_setter(attrs) asw?(attrs,"Class.Property.Set(") end |
.is_a_class_static_method(attrs) ⇒ Object
17 |
# File 'lib/krpc/attributes.rb', line 17 def is_a_class_static_method(attrs) asw?(attrs,"Class.StaticMethod(") end |
.is_a_property_accessor(attrs) ⇒ Object
12 |
# File 'lib/krpc/attributes.rb', line 12 def is_a_property_accessor(attrs) asw?(attrs,"Property.") end |
.is_a_property_getter(attrs) ⇒ Object
13 |
# File 'lib/krpc/attributes.rb', line 13 def is_a_property_getter(attrs) asw?(attrs,"Property.Get(") end |
.is_a_property_setter(attrs) ⇒ Object
14 |
# File 'lib/krpc/attributes.rb', line 14 def is_a_property_setter(attrs) asw?(attrs,"Property.Set(") end |
.is_any_start_with?(attrs, prefix) ⇒ Boolean Also known as: asw?
7 8 9 |
# File 'lib/krpc/attributes.rb', line 7 def is_any_start_with?(attrs, prefix) attrs.any?{|a| a.start_with? prefix } end |