Module: SentimentInsights::Export::Exportable
- Included in:
- Result
- Defined in:
- lib/sentiment_insights/export/exportable.rb
Overview
Module to be extended on result hashes to add export functionality
Instance Method Summary collapse
-
#export(filename_or_format = nil, options = {}) ⇒ String
Export to specified format (auto-detects from filename extension).
-
#export_all(base_filename = nil) ⇒ Object
Export to both CSV and Excel formats.
-
#export_by_segment(segment_type, segment_values, format = :csv, filename = nil) ⇒ Object
Export responses from specific segments.
-
#export_negative(format = :csv, filename = nil) ⇒ Object
Export only negative responses.
-
#export_positive(format = :csv, filename = nil) ⇒ Object
Export only positive responses.
-
#exporter(options = {}) ⇒ SentimentInsights::Export::Exporter
Create an exporter instance for advanced operations.
-
#filter_segments(segment_filters) ⇒ Object
Filter by segment criteria.
-
#filter_sentiment(*sentiments) ⇒ Object
Filter by sentiment.
-
#responses_only ⇒ Object
Export only response data (no summary/segments).
-
#summary_only ⇒ Object
Export only summary data (no individual responses).
-
#to_csv(filename = nil, options = {}) ⇒ String
Export to CSV format.
-
#to_excel(filename = nil, options = {}) ⇒ String
Export to Excel format.
-
#to_hash(options = {}) ⇒ Hash
Return as hash structure (for API responses).
-
#to_json(filename = nil, options = {}) ⇒ String
Export to JSON format.
-
#to_json_string(options = {}) ⇒ String
Return JSON as string (for API responses).
-
#with_export_options(options) ⇒ Object
Configure export with options and return self for chaining.
-
#with_segments ⇒ Object
Include detailed segment analysis.
-
#without_segments ⇒ Object
Exclude segment analysis.
Instance Method Details
#export(filename_or_format = nil, options = {}) ⇒ String
Export to specified format (auto-detects from filename extension)
59 60 61 62 63 |
# File 'lib/sentiment_insights/export/exportable.rb', line 59 def export(filename_or_format = nil, = {}) = (@export_options || {}).merge() exporter = SentimentInsights::Export::Exporter.new(self, ) exporter.export(filename_or_format) end |
#export_all(base_filename = nil) ⇒ Object
Export to both CSV and Excel formats
91 92 93 |
# File 'lib/sentiment_insights/export/exportable.rb', line 91 def export_all(base_filename = nil) exporter.export_all(base_filename) end |
#export_by_segment(segment_type, segment_values, format = :csv, filename = nil) ⇒ Object
Export responses from specific segments
86 87 88 |
# File 'lib/sentiment_insights/export/exportable.rb', line 86 def export_by_segment(segment_type, segment_values, format = :csv, filename = nil) exporter.by_segment(segment_type, segment_values, format, filename) end |
#export_negative(format = :csv, filename = nil) ⇒ Object
Export only negative responses
81 82 83 |
# File 'lib/sentiment_insights/export/exportable.rb', line 81 def export_negative(format = :csv, filename = nil) exporter.negative_only(format, filename) end |
#export_positive(format = :csv, filename = nil) ⇒ Object
Export only positive responses
76 77 78 |
# File 'lib/sentiment_insights/export/exportable.rb', line 76 def export_positive(format = :csv, filename = nil) exporter.positive_only(format, filename) end |
#exporter(options = {}) ⇒ SentimentInsights::Export::Exporter
Create an exporter instance for advanced operations
68 69 70 71 |
# File 'lib/sentiment_insights/export/exportable.rb', line 68 def exporter( = {}) = (@export_options || {}).merge() SentimentInsights::Export::Exporter.new(self, ) end |
#filter_segments(segment_filters) ⇒ Object
Filter by segment criteria
129 130 131 132 133 |
# File 'lib/sentiment_insights/export/exportable.rb', line 129 def filter_segments(segment_filters) current_filter = @export_options&.dig(:filter) || {} new_filter = current_filter.merge(segments: segment_filters) (filter: new_filter) end |
#filter_sentiment(*sentiments) ⇒ Object
Filter by sentiment
124 125 126 |
# File 'lib/sentiment_insights/export/exportable.rb', line 124 def filter_sentiment(*sentiments) (filter: { sentiment: sentiments.flatten }) end |
#responses_only ⇒ Object
Export only response data (no summary/segments)
109 110 111 |
# File 'lib/sentiment_insights/export/exportable.rb', line 109 def responses_only (include_summary: false, include_segments: false) end |
#summary_only ⇒ Object
Export only summary data (no individual responses)
104 105 106 |
# File 'lib/sentiment_insights/export/exportable.rb', line 104 def summary_only (include_segments: false, summary_only: true) end |
#to_csv(filename = nil, options = {}) ⇒ String
Export to CSV format
11 12 13 14 15 |
# File 'lib/sentiment_insights/export/exportable.rb', line 11 def to_csv(filename = nil, = {}) = (@export_options || {}).merge() exporter = SentimentInsights::Export::Exporter.new(self, ) exporter.to_csv(filename) end |
#to_excel(filename = nil, options = {}) ⇒ String
Export to Excel format
21 22 23 24 25 |
# File 'lib/sentiment_insights/export/exportable.rb', line 21 def to_excel(filename = nil, = {}) = (@export_options || {}).merge() exporter = SentimentInsights::Export::Exporter.new(self, ) exporter.to_excel(filename) end |
#to_hash(options = {}) ⇒ Hash
Return as hash structure (for API responses)
49 50 51 52 53 |
# File 'lib/sentiment_insights/export/exportable.rb', line 49 def to_hash( = {}) = (@export_options || {}).merge() exporter = SentimentInsights::Export::Exporter.new(self, ) exporter.to_hash end |
#to_json(filename = nil, options = {}) ⇒ String
Export to JSON format
31 32 33 34 35 |
# File 'lib/sentiment_insights/export/exportable.rb', line 31 def to_json(filename = nil, = {}) = (@export_options || {}).merge() exporter = SentimentInsights::Export::Exporter.new(self, ) exporter.to_json(filename) end |
#to_json_string(options = {}) ⇒ String
Return JSON as string (for API responses)
40 41 42 43 44 |
# File 'lib/sentiment_insights/export/exportable.rb', line 40 def to_json_string( = {}) = (@export_options || {}).merge() exporter = SentimentInsights::Export::Exporter.new(self, ) exporter.to_json_string end |
#with_export_options(options) ⇒ Object
Configure export with options and return self for chaining
98 99 100 101 |
# File 'lib/sentiment_insights/export/exportable.rb', line 98 def () @export_options = (@export_options || {}).merge() self end |
#with_segments ⇒ Object
Include detailed segment analysis
114 115 116 |
# File 'lib/sentiment_insights/export/exportable.rb', line 114 def with_segments (include_segments: true) end |
#without_segments ⇒ Object
Exclude segment analysis
119 120 121 |
# File 'lib/sentiment_insights/export/exportable.rb', line 119 def without_segments (include_segments: false) end |