Class: Macro
- Inherits:
-
Object
- Object
- Macro
- Defined in:
- lib/ruby-macrodroid.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#local_variables ⇒ Object
readonly
Returns the value of attribute local_variables.
-
#name ⇒ Object
Returns the value of attribute name.
-
#triggers ⇒ Object
readonly
Returns the value of attribute triggers.
Instance Method Summary collapse
- #add(obj) ⇒ Object
- #import_h(h) ⇒ Object
- #import_xml(node) ⇒ Object
-
#initialize(name = nil, debug: false) ⇒ Macro
constructor
A new instance of Macro.
- #to_h ⇒ Object
Constructor Details
#initialize(name = nil, debug: false) ⇒ Macro
Returns a new instance of Macro.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ruby-macrodroid.rb', line 122 def initialize(name=nil, debug: false) @name, @debug = name, debug lv=[], triggers=[], actions=[] @local_variables, @triggers, @actions = lv, triggers, actions @triggers, @actions = [], [] @h = {} end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
119 120 121 |
# File 'lib/ruby-macrodroid.rb', line 119 def actions @actions end |
#local_variables ⇒ Object (readonly)
Returns the value of attribute local_variables.
119 120 121 |
# File 'lib/ruby-macrodroid.rb', line 119 def local_variables @local_variables end |
#name ⇒ Object
Returns the value of attribute name.
120 121 122 |
# File 'lib/ruby-macrodroid.rb', line 120 def name @name end |
#triggers ⇒ Object (readonly)
Returns the value of attribute triggers.
119 120 121 |
# File 'lib/ruby-macrodroid.rb', line 119 def triggers @triggers end |
Instance Method Details
#add(obj) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/ruby-macrodroid.rb', line 133 def add(obj) if obj.kind_of? Trigger then puts 'trigger found' if @debug @triggers << obj elsif obj.kind_of? Action puts 'action found' if @debug @actions << obj elsif obj.kind_of? Constraint puts 'constraint found' if @debug @constraints << obj end end |
#import_h(h) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ruby-macrodroid.rb', line 176 def import_h(h) # fetch the local variables @local_variables = h['local_variables'] # fetch the triggers @triggers = h[:trigger_list].map do |trigger| object(trigger.to_snake_case) end @actions = h[:action_list].map do |action| object(action.to_snake_case) end # fetch the constraints (not yet implemented) @h = h %i(local_variables m_trigger_list m_action_list).each do |x| @h[x] = [] end @h end |
#import_xml(node) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/ruby-macrodroid.rb', line 204 def import_xml(node) @name = node.attributes[:name] if node.element('triggers') then # level 2 # get all the triggers @triggers = node.xpath('triggers/*').map do |e| puts 'e.name: ' + e.name.inspect if @debug {timer: TimerTrigger}[e.name.to_sym].new(e.attributes.to_h) end # get all the actions @actions = node.xpath('actions/*').map do |e| if e.name == 'notification' then case e.attributes[:type].to_sym when :popup e.attributes.delete :type ToastAction.new e.attributes.to_h end end end else # Level 1 tp = TriggersNlp.new @triggers = node.xpath('trigger').map do |e| r = tp.find_trigger e.text if r then r[0].new(r[1]) end end ap = ActionsNlp.new @actions = node.xpath('action').map do |e| r = ap.find_action e.text if r then r[0].new(r[1]) end end end self end |
#to_h ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ruby-macrodroid.rb', line 154 def to_h() h = { local_variables: @local_variables, m_trigger_list: @triggers.map(&:to_h), m_action_list: @actions.map(&:to_h), m_constraint_list: [], m_description: '', m_name: @name, m_excludeLog: false, m_GUID: guid(), m_isOrCondition: false, m_enabled: false, m_descriptionOpen: false, m_headingColor: 0 } puts 'h: ' + h.inspect if @debug @h.merge(h) end |