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
- #export_json ⇒ Object (also: #to_json)
- #import_json(s) ⇒ Object
-
#initialize(obj, debug: false) ⇒ MacroDroid
constructor
A new instance of MacroDroid.
- #to_h ⇒ Object
Constructor Details
#initialize(obj, debug: false) ⇒ MacroDroid
Returns a new instance of MacroDroid.
102 103 104 105 106 107 |
# File 'lib/ruby-macrodroid.rb', line 102 def initialize(obj, debug: false) @debug = debug s, _ = RXFHelper.read(obj) import_json(s) if s[0] == '{' end |
Instance Attribute Details
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
100 101 102 |
# File 'lib/ruby-macrodroid.rb', line 100 def macros @macros end |
Instance Method Details
#export_json ⇒ Object Also known as: to_json
109 110 111 112 113 |
# File 'lib/ruby-macrodroid.rb', line 109 def export_json() to_h.to_json end |
#import_json(s) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ruby-macrodroid.rb', line 117 def import_json(s) @h = JSON.parse s puts ('@h: ' + @h.pretty_inspect).debug if @debug @macros = @h["macroList"].map do |macro| puts ('macro: ' + macro.pretty_inspect).debug if @debug m = Macro.new(debug: @debug) m.import_h(macro) m end @h['macroList'] = [] end |
#to_h ⇒ Object
134 135 136 137 138 |
# File 'lib/ruby-macrodroid.rb', line 134 def to_h() @h.merge('macroList' => @macros.map(&:to_h)) end |