Class: Plasticine::Builder::Base
- Inherits:
-
Object
- Object
- Plasticine::Builder::Base
- Defined in:
- lib/plasticine/builder/base.rb
Instance Attribute Summary collapse
-
#visual ⇒ Object
Returns the value of attribute visual.
Instance Method Summary collapse
- #chart_style=(style) ⇒ Object
- #close_visual ⇒ Object
- #id ⇒ Object
-
#initialize(id, options = {}) ⇒ Base
constructor
A new instance of Base.
- #l(date, options = {}) ⇒ Object
- #period ⇒ Object
- #set_period_from_data(data) ⇒ Object
- #t(path, vars = {}) ⇒ Object
- #title ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(id, options = {}) ⇒ Base
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/plasticine/builder/base.rb', line 4 def initialize(id, ={}) .reverse_merge! from: nil, chart_style: 'standard', to: nil, step: nil @from = [:from] ? Time.parse([:from]) : nil @to = [:to] ? Time.parse([:to]) : Time.now @visual = { id: id } @visual[:step] = [:step] if [:step] @visual[:title] = t('title') @visual[:period] = Plasticine::Builder.period(@from, @to, step: @visual[:step]) if @from end |
Instance Attribute Details
#visual ⇒ Object
Returns the value of attribute visual.
2 3 4 |
# File 'lib/plasticine/builder/base.rb', line 2 def visual @visual end |
Instance Method Details
#chart_style=(style) ⇒ Object
20 21 22 |
# File 'lib/plasticine/builder/base.rb', line 20 def chart_style=(style) @visual[:chart_style] = "style-#{style}" end |
#close_visual ⇒ Object
16 17 18 |
# File 'lib/plasticine/builder/base.rb', line 16 def close_visual # Hooks before closing a visual end |
#id ⇒ Object
24 25 26 |
# File 'lib/plasticine/builder/base.rb', line 24 def id @visual[:id] end |
#l(date, options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/plasticine/builder/base.rb', line 28 def l(date, ={}) .reverse_merge!(format: :date_long) Plasticine.localize(date, ) end |
#period ⇒ Object
34 35 36 |
# File 'lib/plasticine/builder/base.rb', line 34 def period @visual[:period] end |
#set_period_from_data(data) ⇒ Object
38 39 40 41 42 43 44 45 |
# 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 = {}) ⇒ Object
47 48 49 50 51 |
# File 'lib/plasticine/builder/base.rb', line 47 def t(path, vars={}) vars.reverse_merge! default: '' Plasticine.translate("#{id.gsub('-', '_')}.#{path}", vars) end |
#title ⇒ Object
53 54 55 |
# File 'lib/plasticine/builder/base.rb', line 53 def title @visual[:title] end |
#to_json ⇒ Object
57 58 59 60 61 |
# File 'lib/plasticine/builder/base.rb', line 57 def to_json close_visual @visual.to_json end |