Class: Trifle::Stats::Formatter::Timeline

Inherits:
Object
  • Object
show all
Defined in:
lib/trifle/stats/formatter/timeline.rb

Instance Method Summary collapse

Instance Method Details

#format(series:, path:, slices: 1, &block) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/trifle/stats/formatter/timeline.rb', line 9

def format(series:, path:, slices: 1, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  return {} if series[:at].empty?

  values = series[:values] || []
  segments = PathUtils.split_path(path)
  resolved_paths = PathUtils.resolve_concrete_paths(values, segments)
  zipped = series[:at].zip(values)

  resolved_paths.each_with_object({}) do |path_segments, acc|
    full_key = path_segments.join('.')
    timeline = zipped.map do |at, data|
      value = PathUtils.fetch_path(data, path_segments)
      [at, value]
    end

    acc[full_key] = formatted_timeline(result: timeline, slices: slices, block: block)
  end
end