Class: IfConditionAction
- Inherits:
-
Action
- Object
- MacroObject
- Action
- IfConditionAction
- Defined in:
- lib/ruby-macrodroid/actions.rb
Overview
Conditions/Loops
Instance Attribute Summary
Attributes inherited from Action
Attributes inherited from MacroObject
Instance Method Summary collapse
-
#initialize(obj = nil) ⇒ IfConditionAction
constructor
A new instance of IfConditionAction.
- #to_s(colour: false, indent: 0) ⇒ Object
Methods inherited from Action
Methods inherited from MacroObject
Constructor Details
#initialize(obj = nil) ⇒ IfConditionAction
Returns a new instance of IfConditionAction.
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/ruby-macrodroid/actions.rb', line 390 def initialize(obj=nil) = { a: true, constraint_list: [] } if obj.is_a? Hash then h = obj macro = h[:macro] h2 = .merge(filter(,h).merge(macro: macro)) super(h2) elsif obj.is_a? Array e, macro = obj super() raw_txt = e.text('item/description') || e.text.to_s puts 'raw_txt: ' + raw_txt.inspect if $debug clause = raw_txt[/^if (.*)/i,1] conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i) cp = ConstraintsNlp.new @constraints = conditions.map do |c| puts 'c: ' + c.inspect r = cp.find_constraint c puts 'found constraint ' + r.inspect if $debug r[0].new(r[1]) if r end puts '@constraints: ' + @constraints.inspect if $debug {} else # get the constraints end @label = 'If ' end |
Instance Method Details
#to_s(colour: false, indent: 0) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/ruby-macrodroid/actions.rb', line 438 def to_s(colour: false, indent: 0) h = @h.clone #h.delete :macro @s = 'If ' operator = @h[:is_or_condition] ? 'OR' : 'AND' constraints = @constraints.map \ {|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator) out = [] out << "; %s" % @h[:comment] if @h[:comment] s = @s.lines.map {|x| (' ' * indent) + x}.join out << s + constraints out.join("\n") end |