Sha256: b2ea7910254efed91927c5642e53cf2526cfc9781f480bbac69233b118b83ecf

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require 'quby/questionnaires/entities/charting/line_chart'
require_relative 'chart_builder'

module Quby
  module Questionnaires
    module DSL
      class LineChartBuilder < ChartBuilder
        set_chart_class(Entities::Charting::LineChart)

        def y_axis_label(label)
          @chart.y_label = label
        end

        def tonality(value)
          @chart.tonality = value
        end

        def baseline(value = nil, &block)
          unless value.nil? ^ block.nil?
            fail ArgumentError, "Must give either value or a block"
          end

          if value
            @chart.baseline = ->(age, gender) { value }
          end

          if block
            if block.arity != 2
              fail ArgumentError, "Given block must take two arguments"
            end
            @chart.baseline = block
          end
        end

        def clinically_relevant_change(value)
          @chart.clinically_relevant_change = value
        end

        def validate!
          fail "Chart #{@chart.key} has no range specified" unless @chart.y_range
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
quby-4.0.2 lib/quby/questionnaires/dsl/charting/line_chart_builder.rb
quby-4.0.1 lib/quby/questionnaires/dsl/charting/line_chart_builder.rb
quby-4.0.0 lib/quby/questionnaires/dsl/charting/line_chart_builder.rb
quby-3.2.2 lib/quby/questionnaires/dsl/charting/line_chart_builder.rb
quby-3.2.1 lib/quby/questionnaires/dsl/charting/line_chart_builder.rb
quby-3.2.0 lib/quby/questionnaires/dsl/charting/line_chart_builder.rb
quby-3.2.0.pre.pre1 lib/quby/questionnaires/dsl/charting/line_chart_builder.rb