Class: DjiMqttConnect::Utils::MqttxFixtureDataGenerator
- Inherits:
-
Object
- Object
- DjiMqttConnect::Utils::MqttxFixtureDataGenerator
- Defined in:
- lib/dji_mqtt_connect/utils/mqttx_fixture_data_generator.rb
Overview
Generates anonymised fixture data from MQTTX JSON Export Dumps
Class Method Summary collapse
Instance Method Summary collapse
-
#generate ⇒ Object
Generates fixture data using ALL found messages in the MQTTX export.
-
#generate_unique(**schema_generator_args) ⇒ Object
Generates fixture data using unique found messages in the MQTTX export.
-
#initialize(mqttx_data, message_sanitizer:) ⇒ MqttxFixtureDataGenerator
constructor
A new instance of MqttxFixtureDataGenerator.
Constructor Details
#initialize(mqttx_data, message_sanitizer:) ⇒ MqttxFixtureDataGenerator
Returns a new instance of MqttxFixtureDataGenerator.
15 16 17 18 |
# File 'lib/dji_mqtt_connect/utils/mqttx_fixture_data_generator.rb', line 15 def initialize(mqttx_data, message_sanitizer:) @mqttx_data = mqttx_data @message_sanitizer = end |
Class Method Details
.from_file(file_path, **sanitizer_args) ⇒ Object
10 11 12 13 |
# File 'lib/dji_mqtt_connect/utils/mqttx_fixture_data_generator.rb', line 10 def self.from_file(file_path, **sanitizer_args) raw_data = File.read(file_path) new JSON.parse(raw_data), message_sanitizer: MessageSanitizer.new(**sanitizer_args) end |
Instance Method Details
#generate ⇒ Object
Generates fixture data using ALL found messages in the MQTTX export
# Output is: <topic 1>: <message 1 as json> <topic 1>: <message 2 as json>
25 26 27 28 29 |
# File 'lib/dji_mqtt_connect/utils/mqttx_fixture_data_generator.rb', line 25 def generate .each_with_object(StringIO.new) do |(topic, ), builder| builder.puts [topic, .to_json].join(": ") end.string end |
#generate_unique(**schema_generator_args) ⇒ Object
Generates fixture data using unique found messages in the MQTTX export
A message is considered unique if the topic and schema does not match any other messages
# Output is: <topic 1>: <message 1 as json>
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dji_mqtt_connect/utils/mqttx_fixture_data_generator.rb', line 37 def generate_unique(**schema_generator_args) = MessageSchemaGenerator.new(**schema_generator_args) = .each_with_object({}) do |(topic, ), found| = .generate() found[[topic, ]] ||= [topic, ] end.values .each_with_object(StringIO.new) do |(topic, ), builder| builder.puts [topic, .to_json].join(": ") end.string end |