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
- #import(s) ⇒ 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 |
# 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 = {} @macros = [] 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 import_txt(s) 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
171 172 173 |
# File 'lib/ruby-macrodroid.rb', line 171 def add(macro) @macros << macro end |
#build_h ⇒ Object
175 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 |
# File 'lib/ruby-macrodroid.rb', line 175 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
203 204 205 |
# File 'lib/ruby-macrodroid.rb', line 203 def export(filepath) FileX.write filepath, to_json end |
#import(s) ⇒ Object
207 208 209 |
# File 'lib/ruby-macrodroid.rb', line 207 def import(s) import_txt(s) end |
#to_h ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/ruby-macrodroid.rb', line 218 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
211 212 213 214 215 |
# File 'lib/ruby-macrodroid.rb', line 211 def to_json() to_h.to_json end |
#to_pc ⇒ Object
returns pseudocode
232 233 234 |
# File 'lib/ruby-macrodroid.rb', line 232 def to_pc() @macros.map(&:to_pc).join("\n\n") end |
#to_s(colour: false) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/ruby-macrodroid.rb', line 236 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
250 251 252 |
# File 'lib/ruby-macrodroid.rb', line 250 def to_summary(colour: false) @macros.map {|x| x.to_summary(colour: colour)}.join("\n") end |