Class: MacroDroid
- Inherits:
-
Object
- Object
- MacroDroid
- Defined in:
- lib/ruby-macrodroid.rb
Instance Attribute Summary collapse
-
#geofences ⇒ Object
readonly
Returns the value of attribute geofences.
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
-
#yaml ⇒ Object
readonly
Returns the value of attribute yaml.
Instance Method Summary collapse
- #add(macro) ⇒ Object
- #build_h ⇒ Object
- #export_json ⇒ Object (also: #to_json)
-
#initialize(obj = nil, debug: false) ⇒ MacroDroid
constructor
A new instance of MacroDroid.
- #to_h ⇒ Object
-
#to_pc ⇒ Object
returns pseudocode.
- #to_s(colour: false) ⇒ Object
- #to_summary(colour: false) ⇒ Object
Constructor Details
#initialize(obj = nil, debug: false) ⇒ MacroDroid
Returns a new instance of MacroDroid.
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 |
# File 'lib/ruby-macrodroid.rb', line 830 def initialize(obj=nil, debug: false) @debug = debug @geofences = {} if obj then raw_s, _ = RXFHelper.read(obj) s = raw_s.strip if s[0] == '{' then import_json(s) elsif s[0] == '<' import_xml(s) @h = build_h else puts 's: ' + s.inspect if @debug if s =~ /m(?:acro)?:\s/ then puts 'before RowX.new' if @debug s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\ .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\ .gsub(/^c:/,'constraint:').gsub(/^#.*/,'') raw_macros, raw_geofences = s2.split(/(?=^macro:)/,2).reverse if raw_geofences then geoxml = RowX.new(raw_geofences).to_xml geodoc = Rexle.new(geoxml) geofences = geodoc.root.xpath('item/geofence') @geofences = fetch_geofences(geofences) if geofences.any? end xml = RowX.new(raw_macros).to_xml import_rowxml(xml) elsif s =~ /^# / xml = pc_to_xml(s) import_xml(xml) else raise MacroDroidError, 'invalid input' end @h = build_h end else @h = build_h() @macros = [] end end |
Instance Attribute Details
#geofences ⇒ Object (readonly)
Returns the value of attribute geofences.
828 829 830 |
# File 'lib/ruby-macrodroid.rb', line 828 def geofences @geofences end |
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
828 829 830 |
# File 'lib/ruby-macrodroid.rb', line 828 def macros @macros end |
#yaml ⇒ Object (readonly)
Returns the value of attribute yaml.
828 829 830 |
# File 'lib/ruby-macrodroid.rb', line 828 def yaml @yaml end |
Instance Method Details
#add(macro) ⇒ Object
898 899 900 |
# File 'lib/ruby-macrodroid.rb', line 898 def add(macro) @macros << macro end |
#build_h ⇒ Object
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 |
# File 'lib/ruby-macrodroid.rb', line 902 def build_h() puts 'inside Macro#build_h' if @debug { cell_tower_groups: [], cell_towers_ignore: [], drawer_configuration: { drawer_items: [], background_color: -1, header_color: 12692882, left_side: false, swipe_area_color: -7829368, swipe_area_height: 20, swipe_area_offset: 40, swipe_area_opacity: 80, swipe_area_width: 14, visible_swipe_area_width: 0 }, variables: [], user_icons: [], geofence_data: { geofence_map: {} }, macro_list: [] } end |
#export_json ⇒ Object Also known as: to_json
930 931 932 933 934 |
# File 'lib/ruby-macrodroid.rb', line 930 def export_json() to_h.to_json end |
#to_h ⇒ Object
939 940 941 942 943 944 945 946 947 948 949 |
# File 'lib/ruby-macrodroid.rb', line 939 def to_h() h = { geofence_data: { geofence_map: @geofences.map {|key, value| [key, value.to_h] }.to_h }, macro_list: @macros.map(&:to_h) } @h.merge(h).to_camel_case end |
#to_pc ⇒ Object
returns pseudocode
953 954 955 |
# File 'lib/ruby-macrodroid.rb', line 953 def to_pc() @macros.map(&:to_pc).join("\n\n") end |
#to_s(colour: false) ⇒ Object
957 958 959 960 961 962 963 964 965 966 967 968 969 |
# File 'lib/ruby-macrodroid.rb', line 957 def to_s(colour: false) lines = [] if @geofences.any? then lines << @geofences.map {|_, value| (colour ? "g".green.bold : 'g') \ + ': ' + value.to_s}.join("\n\n") + "\n" end lines << @macros.map {|x| x.to_s(colour: colour)}.join("\n") lines.join("\n") end |
#to_summary(colour: false) ⇒ Object
971 972 973 |
# File 'lib/ruby-macrodroid.rb', line 971 def to_summary(colour: false) @macros.map {|x| x.to_summary(colour: colour)}.join("\n") end |