class Plasticine::Builder::Base

Attributes

visual[RW]

Public Class Methods

new(id, options={}) click to toggle source
# File lib/plasticine/builder/base.rb, line 4
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

Public Instance Methods

chart_style=(style) click to toggle source
# File lib/plasticine/builder/base.rb, line 20
def chart_style=(style)
  @visual[:chart_style] = "style-#{style}"
end
close_visual() click to toggle source
# File lib/plasticine/builder/base.rb, line 16
def close_visual
  # Hooks before closing a visual
end
id() click to toggle source
# File lib/plasticine/builder/base.rb, line 24
def id
  @visual[:id]
end
l(date, options={}) click to toggle source
# File lib/plasticine/builder/base.rb, line 28
def l(date, options={})
  options.reverse_merge!(format: :date_long)

  Plasticine.localize(date, options)
end
period() click to toggle source
# File lib/plasticine/builder/base.rb, line 34
def period
  @visual[:period]
end
set_period_from_data(data) click to toggle source
# File lib/plasticine/builder/base.rb, line 38
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
t(path, vars={}) click to toggle source
# File lib/plasticine/builder/base.rb, line 47
def t(path, vars={})
  vars.reverse_merge! default: ''

  Plasticine.translate("#{id.gsub('-', '_')}.#{path}", vars)
end
title() click to toggle source
# File lib/plasticine/builder/base.rb, line 53
def title
  @visual[:title]
end
to_json() click to toggle source
# File lib/plasticine/builder/base.rb, line 57
def to_json
  close_visual

  @visual.to_json
end