Sha256: d62aa5f235fc0da29a236464d0103b76df1c06e7bdb786ab4b92416216f184da

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

module LatoCore

  class Charts::Bar::Vertical::Cell < Cell

    @@requested_args = [:labels, :datasets]

    @@default_args = {

    }

    def initialize(args = {})
      @args = validate_args(
        args: args,
        requested_args: @@requested_args,
        default_args: @@default_args
      )

      validates_labels
      validates_datasets
      set_conditions
    end

    def show
      render 'show.html'
    end

    private

    def set_conditions
      @metadata = {
        chart_type: 'bar',
        labels: @args[:labels],
        datasets: @args[:datasets]
      }
    end

    def validates_labels
      raise 'Chart labels is not an array' unless @args[:labels].is_a?(Array)
    end

    def validates_datasets
      raise 'Chart datasets is not an array' unless @args[:datasets].is_a?(Array)

      @args[:datasets].each do |dataset|
        validates_dataset(dataset)
      end
    end

    def validates_dataset(dataset)
      raise 'Chart dataset has not a label' unless dataset[:label]
      raise 'Chart dataset data is not an array' unless dataset[:data].is_a?(Array)
      raise 'Chart dataset data length in not correct' unless dataset[:data].length == @args[:labels].length
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lato_core-2.2.2 app/cells/lato_core/charts/bar/vertical/cell.rb
lato_core-2.2.0 app/cells/lato_core/charts/bar/vertical/cell.rb
lato_core-2.1.4 app/cells/lato_core/charts/bar/vertical/cell.rb
lato_core-2.1.3 app/cells/lato_core/charts/bar/vertical/cell.rb
lato_core-2.1.2 app/cells/lato_core/charts/bar/vertical/cell.rb
lato_core-2.1.1 app/cells/lato_core/charts/bar/vertical/cell.rb
lato_core-2.1 app/cells/lato_core/charts/bar/vertical/cell.rb