Class: MacroDroid

Inherits:
Object
  • Object
show all
Includes:
RXFHelperModule
Defined in:
lib/ruby-macrodroid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#deviceidObject

Returns the value of attribute deviceid.



113
114
115
# File 'lib/ruby-macrodroid.rb', line 113

def deviceid
  @deviceid
end

#geofencesObject (readonly)

Returns the value of attribute geofences.



112
113
114
# File 'lib/ruby-macrodroid.rb', line 112

def geofences
  @geofences
end

#macrosObject (readonly)

Returns the value of attribute macros.



112
113
114
# File 'lib/ruby-macrodroid.rb', line 112

def macros
  @macros
end

#picture_pathObject

Returns the value of attribute picture_path.



113
114
115
# File 'lib/ruby-macrodroid.rb', line 113

def picture_path
  @picture_path
end

#remote_urlObject

Returns the value of attribute remote_url.



113
114
115
# File 'lib/ruby-macrodroid.rb', line 113

def remote_url
  @remote_url
end

#yamlObject (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_hObject



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_hObject



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_jsonObject



211
212
213
214
215
# File 'lib/ruby-macrodroid.rb', line 211

def to_json()

  to_h.to_json

end

#to_pcObject

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