class NexosisApi::ViewDefinition

class to hold the parsed results of a view @since 1.2.0

Attributes

column_metadata[RW]

Descriptive information about the columns @return [Array of NexosisApi::Column]

dataset_name[RW]

The name of the dataset on the left of the join @return [String]

is_timeseries[RW]

Is this view based on time series data? @since 1.3.0

joins[RW]

The join configuration for this view @return [Array of NexosisApi::Join]

timeseries?[RW]

Is this view based on time series data? @since 1.3.0

view_name[RW]

The name of the view uploaded and saved @return [String]

Public Class Methods

new(view_hash) click to toggle source
# File lib/nexosis_api/view_definition.rb, line 5
def initialize(view_hash)
  view_hash.each do |k, v|
    if k == 'viewName'
      @view_name = v unless v.nil?
    elsif k == 'dataSetName'
      @dataset_name = v unless v.nil?
    elsif k == 'columns'
      next if v.nil?
      @column_metadata = v.reject { |value| value.nil? } .map { |col_name, col_hash| NexosisApi::Column.new(col_name, col_hash)}
    elsif k == 'joins'
      next if v.nil?
      @joins = v.reject(&:nil?).map { |join| NexosisApi::Join.new(join) }
    elsif k == 'isTimeSeries'
      @is_timeseries = v
    end
  end
end

Public Instance Methods

to_json() click to toggle source

Provides a custom hash which matches json of api request

# File lib/nexosis_api/view_definition.rb, line 48
def to_json
  hash = {}
  hash['dataSetName'] = dataset_name
  if column_metadata.nil? == false
    hash['columns'] = {}
    column_metadata.each do |column|
      hash['columns'].merge!(column.to_hash)
    end
  end
  hash['joins'] = []
  joins.each do |join|
    hash['joins'] << join.to_hash
  end
  hash.to_json
end