Class: TableauServerClient::Resources::Datasource::DatasourceContent

Inherits:
Object
  • Object
show all
Defined in:
lib/tableau_server_client/resources/datasource.rb

Defined Under Namespace

Classes: NamedConnection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ DatasourceContent

Returns a new instance of DatasourceContent.



60
61
62
# File 'lib/tableau_server_client/resources/datasource.rb', line 60

def initialize(xml)
  @xml = xml
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



64
65
66
# File 'lib/tableau_server_client/resources/datasource.rb', line 64

def xml
  @xml
end

Instance Method Details

#custom_queriesObject



73
74
75
# File 'lib/tableau_server_client/resources/datasource.rb', line 73

def custom_queries
  relations.select {|r| r['type'] == 'text' }.map {|c| c.content }
end

#named_connectionsObject



67
68
69
70
71
# File 'lib/tableau_server_client/resources/datasource.rb', line 67

def named_connections
  xml.xpath('//named-connection').map do |c|
    NamedConnection.new(c.first_element_child['class'], c['caption'], c['name'])
  end
end

#tablesObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/tableau_server_client/resources/datasource.rb', line 77

def tables
  tables  = []
  redshift_connections = named_connections.select {|c| c.class == 'redshift' }.map {|c| c.name }
  relations.each do |rel|
    next unless redshift_connections.include? rel['connection']
    case rel['type']
    when 'table'
      tables << rel['table']
    when 'text'
      tables.concat extract_tables(rel.content)
    else
      next
    end
  end
  tables.map {|t| t.gsub(/[\[\]")]/, '')}.uniq
end