Class: NexosisApi::Join

Inherits:
Object
  • Object
show all
Defined in:
lib/nexosis_api/join.rb

Overview

class to hold a join defintion initialized by a hash of join values

Since:

  • 1.2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(join_hash) ⇒ Join

Returns a new instance of Join.

Since:

  • 1.2.0



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nexosis_api/join.rb', line 7

def initialize(join_hash)
  join_hash.each do |k, v|
    if k == 'dataSet'
      @join_target = NexosisApi::DatasetJoinTarget.new(v) unless v.nil?
    elsif k == 'calendar'
      @join_target = NexosisApi::CalendarJoinTarget.new(v) unless v.nil?
    elsif k == 'columnOptions'
      next if v.nil?
      @column_options = v.map do |key, option|
        NexosisApi::ColumnOptions.new(key, option)
      end
    elsif k == 'joins'
      next if v.nil?
      @joins = v.map do |join|
        NexosisApi::Join.new(join)
      end
    end
  end
end

Instance Attribute Details

#column_optionsArray of NexosisApi::ColumnOptions

The optional column definition for the join which defines how columns should be used from the joined dataset

Returns:

Since:

  • 1.2.0



34
35
36
# File 'lib/nexosis_api/join.rb', line 34

def column_options
  @column_options
end

#join_targetObject

The details of the data source that will be participating in the join

Returns:

  • (Object)

    details of the join target

Since:

  • 1.2.0



29
30
31
# File 'lib/nexosis_api/join.rb', line 29

def join_target
  @join_target
end

#joinsArray of NexosisApi::Join

Optional additional data source to be joined to this data source

Returns:

Since:

  • 1.2.0



38
39
40
# File 'lib/nexosis_api/join.rb', line 38

def joins
  @joins
end

Instance Method Details

#to_hashObject

provides a custom hash which can be converted to json matching api request

Since:

  • 1.2.0



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nexosis_api/join.rb', line 41

def to_hash
  hash = join_target.to_hash
  if column_options.nil? == false
    hash['columnOptions'] = {}
    column_options.each do |column|
      hash['columnOptions'].merge!(column.to_hash)
    end
  end
  if joins.nil? == false
    hash['joins'] = []
    joins.each do |join|
      hash['joins'] << join.to_hash
    end
  end
  hash
end

#to_jsonObject

gets a json represenation which can be used in api request

Since:

  • 1.2.0



59
60
61
# File 'lib/nexosis_api/join.rb', line 59

def to_json
  to_hash.to_json
end