Class: MacroDroid
- Inherits:
-
Object
- Object
- MacroDroid
- Includes:
- RXFHelperModule
- Defined in:
- lib/ruby-macrodroid.rb
Instance Attribute Summary collapse
-
#deviceid ⇒ Object
Returns the value of attribute deviceid.
-
#geofences ⇒ Object
readonly
Returns the value of attribute geofences.
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
-
#picture_path ⇒ Object
Returns the value of attribute picture_path.
-
#remote_url ⇒ Object
Returns the value of attribute remote_url.
-
#yaml ⇒ Object
readonly
Returns the value of attribute yaml.
Instance Method Summary collapse
- #add(macro) ⇒ Object
- #build_h ⇒ Object
- #export(filepath) ⇒ Object
-
#initialize(obj = nil, deviceid: nil, remote_url: nil, picture_path: '/storage/emulated/0/Pictures', debug: false) ⇒ MacroDroid
constructor
note: The deviceid can only be found from an existing Webhook trigger, generated from MacroDroid itself.
- #to_h ⇒ Object
- #to_json ⇒ Object
-
#to_pc ⇒ Object
returns pseudocode.
- #to_s(colour: false) ⇒ Object
- #to_summary(colour: false) ⇒ Object
Constructor Details
#initialize(obj = nil, deviceid: nil, remote_url: nil, picture_path: '/storage/emulated/0/Pictures', debug: false) ⇒ MacroDroid
note: The deviceid can only be found from an existing Webhook trigger,
generated from MacroDroid itself.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ruby-macrodroid.rb', line 118 def initialize(obj=nil, deviceid: nil, remote_url: nil, picture_path: '/storage/emulated/0/Pictures', debug: false) @deviceid, @remote_url, @debug = deviceid, remote_url, debug @picture_path = picture_path @geofences = {} if obj then raw_s, _ = RXFHelper.read(obj) s = raw_s.strip if s[0] == '{' then import_json(s) puts 'after import_json' if @debug 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(/^d:/,'description:').gsub(/^v:/,'variable:')\ .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\ .gsub(/^c:/,'constraint:').gsub(/^#.*/,'') a = s2.split(/(?=^macro:)/) raw_geofences = a.shift if a.first =~ /^geofence/ raw_macros = a.join #raw_macros, raw_geofences .reverse puts 'raw_macros: ' + raw_macros.inspect if @debug 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, allow_lonely_keyfield: true).to_xml puts 'xml: ' + xml if @debug 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
#deviceid ⇒ Object
Returns the value of attribute deviceid.
113 114 115 |
# File 'lib/ruby-macrodroid.rb', line 113 def deviceid @deviceid end |
#geofences ⇒ Object (readonly)
Returns the value of attribute geofences.
112 113 114 |
# File 'lib/ruby-macrodroid.rb', line 112 def geofences @geofences end |
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
112 113 114 |
# File 'lib/ruby-macrodroid.rb', line 112 def macros @macros end |
#picture_path ⇒ Object
Returns the value of attribute picture_path.
113 114 115 |
# File 'lib/ruby-macrodroid.rb', line 113 def picture_path @picture_path end |
#remote_url ⇒ Object
Returns the value of attribute remote_url.
113 114 115 |
# File 'lib/ruby-macrodroid.rb', line 113 def remote_url @remote_url end |
#yaml ⇒ Object (readonly)
Returns the value of attribute yaml.
112 113 114 |
# File 'lib/ruby-macrodroid.rb', line 112 def yaml @yaml end |
Instance Method Details
#add(macro) ⇒ Object
197 198 199 |
# File 'lib/ruby-macrodroid.rb', line 197 def add(macro) @macros << macro end |
#build_h ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/ruby-macrodroid.rb', line 201 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(filepath) ⇒ Object
229 230 231 |
# File 'lib/ruby-macrodroid.rb', line 229 def export(filepath) FileX.write filepath, to_json end |
#to_h ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/ruby-macrodroid.rb', line 240 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_camelcase end |
#to_json ⇒ Object
233 234 235 236 237 |
# File 'lib/ruby-macrodroid.rb', line 233 def to_json() to_h.to_json end |
#to_pc ⇒ Object
returns pseudocode
254 255 256 |
# File 'lib/ruby-macrodroid.rb', line 254 def to_pc() @macros.map(&:to_pc).join("\n\n") end |
#to_s(colour: false) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/ruby-macrodroid.rb', line 258 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
272 273 274 |
# File 'lib/ruby-macrodroid.rb', line 272 def to_summary(colour: false) @macros.map {|x| x.to_summary(colour: colour)}.join("\n") end |