Class: SentimentInsights::Export::JsonExporter
- Inherits:
-
BaseExporter
- Object
- BaseExporter
- SentimentInsights::Export::JsonExporter
- Defined in:
- lib/sentiment_insights/export/json_exporter.rb
Instance Attribute Summary
Attributes inherited from BaseExporter
#analysis_type, #options, #result
Instance Method Summary collapse
- #export(filename = nil) ⇒ Object
-
#to_hash ⇒ Object
Return raw hash structure (for API responses).
-
#to_json_string ⇒ Object
Return JSON string without writing to file.
Methods inherited from BaseExporter
Constructor Details
This class inherits a constructor from SentimentInsights::Export::BaseExporter
Instance Method Details
#export(filename = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sentiment_insights/export/json_exporter.rb', line 7 def export(filename = nil) filename ||= generate_filename("json") # Apply filters if specified filtered_result = apply_filters(@result) structured_data = build_json_structure(filtered_result) if filename File.write(filename, JSON.pretty_generate(structured_data)) filename else structured_data # Return data directly for API responses end end |
#to_hash ⇒ Object
Return raw hash structure (for API responses)
30 31 32 |
# File 'lib/sentiment_insights/export/json_exporter.rb', line 30 def to_hash build_json_structure(apply_filters(@result)) end |
#to_json_string ⇒ Object
Return JSON string without writing to file
24 25 26 27 |
# File 'lib/sentiment_insights/export/json_exporter.rb', line 24 def to_json_string structured_data = build_json_structure(apply_filters(@result)) JSON.pretty_generate(structured_data) end |