Class: Trevl::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/trevl/renderer.rb,
lib/trevl/renderer/transform.rb,
lib/trevl/renderer/ref_parser.rb,
lib/trevl/renderer/data_fetcher.rb

Defined Under Namespace

Classes: DataFetcher, RefParser, Transform

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_hash, query_params = {}, data_sources: {}, data: nil) ⇒ Renderer

Returns a new instance of Renderer.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/trevl/renderer.rb', line 11

def initialize(component_hash, query_params = {}, data_sources: {}, data: nil)
  @component = component_hash
  @query_params = query_params || {}
  @data_sources = normalize_data_sources(data_sources)
  @inline_source = data ? DataSource::Static.new(data: data) : nil
  @raw_data = {}
  @warnings = []
  @refs = RefParser.new
  @fetcher = DataFetcher.new
  @transform = Transform.new(@refs)
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



9
10
11
# File 'lib/trevl/renderer.rb', line 9

def component
  @component
end

#data_sourcesObject (readonly)

Returns the value of attribute data_sources.



9
10
11
# File 'lib/trevl/renderer.rb', line 9

def data_sources
  @data_sources
end

#inline_sourceObject (readonly)

Returns the value of attribute inline_source.



9
10
11
# File 'lib/trevl/renderer.rb', line 9

def inline_source
  @inline_source
end

#query_paramsObject (readonly)

Returns the value of attribute query_params.



9
10
11
# File 'lib/trevl/renderer.rb', line 9

def query_params
  @query_params
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



9
10
11
# File 'lib/trevl/renderer.rb', line 9

def raw_data
  @raw_data
end

#warningsObject (readonly)

Returns the value of attribute warnings.



9
10
11
# File 'lib/trevl/renderer.rb', line 9

def warnings
  @warnings
end

Class Method Details

.coerce_fetch_payload(result) ⇒ Object



35
# File 'lib/trevl/renderer.rb', line 35

def self.coerce_fetch_payload(result) = DataFetcher.new.coerce_payload(result)

.deep_dig_indifferent(obj, keys) ⇒ Object



36
# File 'lib/trevl/renderer.rb', line 36

def self.deep_dig_indifferent(obj, keys) = RefParser.new.dig(obj, keys)

.parse_trevl_ref(ref) ⇒ Object

Public class methods kept for backward compatibility and testing



34
# File 'lib/trevl/renderer.rb', line 34

def self.parse_trevl_ref(ref) = RefParser.new.parse(ref)

Instance Method Details

#renderObject



23
24
25
26
27
28
29
30
31
# File 'lib/trevl/renderer.rb', line 23

def render
  case component["type"]
  when "text" then render_text
  when "filter" then has_api? ? render_filter : nil
  when "table" then has_api? ? render_table : nil
  when "score" then has_api? ? render_score : nil
  when "chart" then has_api? ? render_chart : nil
  end
end