Class: MacroObject
- Inherits:
-
Object
- Object
- MacroObject
- Defined in:
- lib/ruby-macrodroid.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#siguid ⇒ Object
readonly
Returns the value of attribute siguid.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(h = {}) ⇒ MacroObject
constructor
A new instance of MacroObject.
- #to_h ⇒ Object
- #to_s(colour: false) ⇒ Object (also: #to_summary)
Constructor Details
#initialize(h = {}) ⇒ MacroObject
Returns a new instance of MacroObject.
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 |
# File 'lib/ruby-macrodroid.rb', line 1154 def initialize(h={}) $env ||= {} @attributes = %i(constraint_list is_or_condition is_disabled siguid) @h = {constraint_list: [], is_or_condition: false, is_disabled: false, siguid: nil}.merge(h) @list = [] # fetch the class name and convert from camelCase to snake_eyes @type = self.class.to_s.sub(/Trigger|Action$/,'')\ .gsub(/\B[A-Z][a-z]/){|x| '_' + x.downcase}\ .gsub(/[a-z][A-Z]/){|x| x[0] + '_' + x[1].downcase}\ .downcase.to_sym @constraints = [] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
1152 1153 1154 |
# File 'lib/ruby-macrodroid.rb', line 1152 def @options end |
#siguid ⇒ Object (readonly)
Returns the value of attribute siguid.
1151 1152 1153 |
# File 'lib/ruby-macrodroid.rb', line 1151 def siguid @siguid end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
1151 1152 1153 |
# File 'lib/ruby-macrodroid.rb', line 1151 def type @type end |
Instance Method Details
#to_h ⇒ Object
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
# File 'lib/ruby-macrodroid.rb', line 1171 def to_h() h = @h h2 = h.inject({}) do |r,x| puts 'x: ' + x.inspect if @debug key, value = x puts 'key: ' + key.inspect if @debug new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase} new_key = new_key.prepend 'm_' unless @list.include? new_key new_key = 'm_SIGUID' if new_key == 'm_siguid' r.merge(new_key => value) end h2.merge('m_classType' => self.class.to_s) end |
#to_s(colour: false) ⇒ Object Also known as: to_summary
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
# File 'lib/ruby-macrodroid.rb', line 1193 def to_s(colour: false) h = @h.clone h.delete :macro @s ||= "#<%s %s>" % [self.class, h.inspect] operator = @h[:is_or_condition] ? 'OR' : 'AND' constraints = @constraints.map \ {|x| x.to_summary(colour: colour)}.join(" %s " % operator) @s + constraints end |