Class: OembedProxy::Tableau
- Inherits:
-
Object
- Object
- OembedProxy::Tableau
- Defined in:
- lib/oembed_proxy/tableau.rb
Overview
Tableau Fauxembed
Constant Summary collapse
- TABLEAU_REGEX =
%r{\Ahttps://public\.tableau\.com/(?:profile/[^/]+/vizhome|views)/([^?]+)}.freeze
Class Method Summary collapse
-
.build_div_id(chart_id) ⇒ Object
Make a unique div_id by slapping a random 10-digit number on the end.
Instance Method Summary collapse
-
#get_data(url, _other_params = {}) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #handles_url?(url) ⇒ Boolean
Class Method Details
.build_div_id(chart_id) ⇒ Object
Make a unique div_id by slapping a random 10-digit number on the end
45 46 47 48 |
# File 'lib/oembed_proxy/tableau.rb', line 45 def self.build_div_id(chart_id) chart_slug = chart_id.parameterize format('%<slug>s-%<rand>010d', slug: chart_slug, rand: rand(1_000_000_000)) end |
Instance Method Details
#get_data(url, _other_params = {}) ⇒ Object
rubocop:disable Metrics/MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oembed_proxy/tableau.rb', line 16 def get_data(url, _other_params = {}) # rubocop:disable Metrics/MethodLength return nil unless handles_url? url chart_id = url.match(TABLEAU_REGEX)[1] div_id = self.class.build_div_id(chart_id) { 'type' => 'rich', 'version' => '1.0', 'provider_name' => 'Tableau', 'provider_url' => 'https://tableau.com/', 'width' => 500, 'height' => 500, 'html' => <<~HTML, <div id="#{div_id}"></div> <script type="text/javascript" src="https://public.tableau.com/javascripts/api/tableau-2.min.js"></script> <script type="text/javascript"> (function() { var container = document.getElementById('#{div_id}'); var url = 'https://public.tableau.com/views/#{chart_id}?:embed=y&:display_count=yes'; var options = {}; var viz = new tableau.Viz(container, url, options); })(); </script> HTML } end |
#handles_url?(url) ⇒ Boolean
12 13 14 |
# File 'lib/oembed_proxy/tableau.rb', line 12 def handles_url?(url) !TABLEAU_REGEX.match(url).nil? end |