Class: IfAction
- Inherits:
-
Action
- Object
- MacroObject
- Action
- IfAction
- Defined in:
- lib/ruby-macrodroid/actions.rb
Overview
Conditions/Loops
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Action
Attributes inherited from MacroObject
Instance Method Summary collapse
-
#initialize(obj = nil) ⇒ IfAction
constructor
A new instance of IfAction.
- #to_s(colour: false, indent: 0) ⇒ Object
Methods inherited from Action
Methods included from ObjectX
#action_to_object, #object_create, #varify
Methods inherited from MacroObject
Constructor Details
#initialize(obj = nil) ⇒ IfAction
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/ruby-macrodroid/actions.rb', line 589 def initialize(obj=nil) $debug = false = { a: true, constraint_list: [] } puts 'obj: ' + obj.inspect if $debug 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() puts 'e.xml: ' + e.xml if $debug puts 'e.text: ' + e.text.to_s.strip if $debug raw_txt = e.text.to_s.strip[/^#{@label}[^$]+/i] || e.text('item/description') puts 'raw_txt: ' + raw_txt.inspect if $debug clause = raw_txt[/^#{@label}(.*)/i,1] puts 'clause: ' + clause.inspect if $debug conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i) puts 'conditions: ' + conditions.inspect if $debug cp = ConstraintsNlp.new @constraints = conditions.map do |c| puts 'c: ' + c.inspect if $debug 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 # find any nested actions item = e.element('item') #puts ('item: ' + item.xml.inspect).debug if $debug if item then ap = ActionsNlp.new obj2 = action_to_object(ap, item, item, macro) puts 'obj2: ' + obj2.inspect if $debug #macro.add obj2 end h = { constraint_list: @constraints.map(&:to_h) } super(h) {} else # get the constraints end end |
Instance Method Details
#to_s(colour: false, indent: 0) ⇒ Object
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'lib/ruby-macrodroid/actions.rb', line 657 def to_s(colour: false, indent: 0) h = @h.clone #h.delete :macro @s = @label 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 |