Class: MacroDroid
- Inherits:
-
Object
- Object
- MacroDroid
- Defined in:
- lib/ruby-macrodroid.rb
Instance Attribute Summary collapse
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
Instance Method Summary collapse
- #add(macro) ⇒ Object
- #build_h ⇒ Object
- #export_json ⇒ Object (also: #to_json)
- #import_json(s) ⇒ Object
- #import_xml(raws) ⇒ Object
-
#initialize(obj = nil, debug: false) ⇒ MacroDroid
constructor
A new instance of MacroDroid.
- #to_h ⇒ Object
Constructor Details
#initialize(obj = nil, debug: false) ⇒ MacroDroid
Returns a new instance of MacroDroid.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/ruby-macrodroid.rb', line 291 def initialize(obj=nil, debug: false) @debug = debug if obj then s, _ = RXFHelper.read(obj) if s[0] == '{' then import_json(s) else s[0] == '<' import_xml(s) @h = build_h end else @h = build_h() @macros = [] end end |
Instance Attribute Details
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
289 290 291 |
# File 'lib/ruby-macrodroid.rb', line 289 def macros @macros end |
Instance Method Details
#add(macro) ⇒ Object
316 317 318 |
# File 'lib/ruby-macrodroid.rb', line 316 def add(macro) @macros << macro end |
#build_h ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/ruby-macrodroid.rb', line 320 def build_h() { 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
347 348 349 350 351 |
# File 'lib/ruby-macrodroid.rb', line 347 def export_json() to_h.to_json end |
#import_json(s) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/ruby-macrodroid.rb', line 355 def import_json(s) @h = JSON.parse(s, symbolize_names: true).to_snake_case puts ('@h: ' + @h.pretty_inspect).debug if @debug @macros = @h[:macro_list].map do |macro| puts ('macro: ' + macro.pretty_inspect).debug if @debug m = Macro.new(debug: @debug) m.import_h(macro) m end @h[:macro_list] = [] end |
#import_xml(raws) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/ruby-macrodroid.rb', line 373 def import_xml(raws) s = RXFHelper.read(raws).first puts 's: ' + s.inspect if @debug doc = Rexle.new(s) puts 'after doc' if @debug @macros = doc.root.xpath('macro').map do |node| macro = Macro.new @name macro.import_xml(node) macro end end |
#to_h ⇒ Object
389 390 391 392 393 |
# File 'lib/ruby-macrodroid.rb', line 389 def to_h() @h.merge(macro_list: @macros.map(&:to_h)).to_camel_case end |