Sha256: 2c0ae1dd04db91aacdd751ec24accf7c51b1d36d259a690cd9c296e77ac56e10

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

module PulseMeter
  module Visualize
    module DSL
      WIDGETS = %w(pie spline line area)
      DEFAULT_HIGHCHART_OPTIONS = {}

      class Page
        def initialize(title = nil)
          @title = title || ""
          @widgets = []
          @highchart_options = DEFAULT_HIGHCHART_OPTIONS.dup
        end

        def widget(type, title = '', widget_args = nil, &block) 
          w = PulseMeter::Visualize::DSL::Widget.new(type, title)
          w.process_args(widget_args) if widget_args
          yield(w) if block_given?
          @widgets << w
        end

        WIDGETS.each do |wtype|
          class_eval <<-EVAL
            def #{wtype}(title = '', args = nil, &block)
              widget(:#{wtype}, title, args, &block)
            end
          EVAL
        end

        def title(new_title)
          @title = new_title || ''
        end

        def highchart_options(options = {})
          @highchart_options.merge!(options)
        end

        def to_page
          args = {
            title: @title,
            widgets: @widgets.map(&:to_widget),
            highchart_options: @highchart_options
          }
          PulseMeter::Visualize::Page.new(args)
        end

      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pulse-meter-0.1.11 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.10 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.9 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.8 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.7 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.6 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.5 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.4 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.3 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.2 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.1 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.1.0 lib/pulse-meter/visualize/dsl/page.rb
pulse-meter-0.0.1 lib/pulse-meter/visualize/dsl/page.rb