Class: CTG::Response::CSVResponse

Inherits:
CTG::Response show all
Defined in:
lib/ctg/response/csv_response.rb

Instance Attribute Summary collapse

Attributes inherited from CTG::Response

#client

Instance Method Summary collapse

Methods inherited from CTG::Response

#next_page, parse

Constructor Details

#initialize(response_body, client) ⇒ CSVResponse

Initializes the CSVResponse object by parsing the CSV data

Parameters:

  • response_body (String)
    • The raw CSV response body from the API

  • client (CTG)
    • The client instance to use for fetching subsequent pages



21
22
23
24
# File 'lib/ctg/response/csv_response.rb', line 21

def initialize(response_body, client)
  super(client)
  @data = CSV.parse(response_body, headers: true)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/ctg/response/csv_response.rb', line 16

def data
  @data
end

Instance Method Details

#query(column_name) ⇒ Array<String>

Queries the CSV data by column name

Parameters:

  • column_name (String)
    • The name of the column to query

Returns:

  • (Array<String>)
    • An array of values from the specified column



29
30
31
# File 'lib/ctg/response/csv_response.rb', line 29

def query(column_name)
  @data.map { |row| row[column_name] }.compact
end