Class: InfluxDB2::FluxCsvParser
- Inherits:
-
Object
- Object
- InfluxDB2::FluxCsvParser
- Includes:
- Enumerable
- Defined in:
- lib/influxdb2/client/flux_csv_parser.rb
Overview
This class us used to construct FluxResult from CSV.
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(response, stream: false, response_mode: InfluxDB2::FluxResponseMode::FULL) ⇒ FluxCsvParser
constructor
A new instance of FluxCsvParser.
- #parse ⇒ Object
Constructor Details
#initialize(response, stream: false, response_mode: InfluxDB2::FluxResponseMode::FULL) ⇒ FluxCsvParser
Returns a new instance of FluxCsvParser.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/influxdb2/client/flux_csv_parser.rb', line 60 def initialize(response, stream: false, response_mode: InfluxDB2::FluxResponseMode::FULL) @response = response @stream = stream @tables = [] @table_index = 0 @table_id = -1 @start_new_table = false @table = nil @groups = [] @parsing_state_error = false @closed = false @response_mode = response_mode end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
76 77 78 |
# File 'lib/influxdb2/client/flux_csv_parser.rb', line 76 def closed @closed end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
76 77 78 |
# File 'lib/influxdb2/client/flux_csv_parser.rb', line 76 def tables @tables end |
Instance Method Details
#each ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/influxdb2/client/flux_csv_parser.rb', line 105 def each return enum_for(:each) unless block_given? parse do |record| yield record end self ensure _close_connection end |
#parse ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/influxdb2/client/flux_csv_parser.rb', line 78 def parse @csv_file = CSV.new(@response.instance_of?(Net::HTTPOK) ? @response.body : @response) while (csv = @csv_file.shift) # Response has HTTP status ok, but response is error. next if csv.empty? if csv[1] == 'error' && csv[2] == 'reference' @parsing_state_error = true next end # Throw InfluxException with error response if @parsing_state_error error = csv[1] reference_value = csv[2] raise FluxQueryError.new(error, reference_value.nil? || reference_value.empty? ? 0 : reference_value.to_i) end result = _parse_line(csv) yield result if @stream && result.instance_of?(InfluxDB2::FluxRecord) end self end |