Sha256: d20c6a41641b3a73c34ea60dc459b5abe0015b0012f2e088b388b3d87554eb65

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

class Plasticine::Builder::Base
  attr_accessor :visual

  def initialize(id, options={})
    options.reverse_merge! from: nil, chart_style: 'standard', to: nil, step: nil

    @from = options[:from] ? Time.parse(options[:from]) : nil
    @to = options[:to] ? Time.parse(options[:to]) : Time.now

    @visual = { id: id }
    @visual[:step] = options[:step] if options[:step]
    @visual[:title] = t('title')
    @visual[:period] = Plasticine::Builder.period(@from, @to, step: @visual[:step]) if @from
  end

  def close_visual
    # Hooks before closing a visual
  end

  def chart_style=(style)
    @visual[:chart_style] = "style-#{style}"
  end

  def id
    @visual[:id]
  end

  def l(date, options={})
    options.reverse_merge!(format: :date_long)

    Plasticine.localize(date, options)
  end

  def period
    @visual[:period]
  end

  def set_period_from_data(data)
    @from = data.first
    @to = data.last

    @visual[:step] = Plasticine::Builder.get_step_from_interval(data[1] - data[0]) if not @visual[:step]

    @visual[:period] = Plasticine::Builder.period @from, @to, step: @visual[:step]
  end

  def t(path, vars={})
    vars.reverse_merge! default: ''

    Plasticine.translate("#{id.gsub('-', '_')}.#{path}", vars)
  end

  def title
    @visual[:title]
  end

  def to_json
    close_visual

    @visual.to_json
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
plasticine-1.2.8 lib/plasticine/builder/base.rb
plasticine-1.2.7 lib/plasticine/builder/base.rb
plasticine-1.2.6 lib/plasticine/builder/base.rb
plasticine-1.2.5 lib/plasticine/builder/base.rb
plasticine-1.2.4 lib/plasticine/builder/base.rb
plasticine-1.2.3 lib/plasticine/builder/base.rb
plasticine-1.2.2 lib/plasticine/builder/base.rb
plasticine-1.2.1 lib/plasticine/builder/base.rb