Module: Plasticine::Builder

Defined in:
lib/plasticine/builder.rb

Defined Under Namespace

Classes: Base, Column, Line

Class Method Summary collapse

Class Method Details

.get_step_from_interval(interval) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/plasticine/builder.rb', line 29

def self.get_step_from_interval(interval)
  days = (interval / (3600 * 24)).to_i.abs

  return case days
    when 0..5 then 'day'
    when 6..27 then 'week'
    when 28..88 then 'month'
    when 89..363 then 'quarter'
    else 'year'
  end
end

.period(start_at, end_at, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/plasticine/builder.rb', line 2

def self.period(start_at, end_at, options={})
  options.reverse_merge!(step: 'day')

  start_at_format = case
    when options[:step] == 'month' then :date_without_day
    when options[:step] == 'year' then :year
    when start_at.year != end_at.year then :date_long
    when start_at.month != end_at.month then :date_long_without_year
    else :day
  end

  end_at_format = case options[:step]
    when 'month' then :date_without_day
    when 'year' then :year
    else :date_long
  end

  content = []
  content << Plasticine.localize(start_at, format: start_at_format)
  content << (['month', 'year'].include?(options[:step]) ? Plasticine.t('date.period.to_month') : Plasticine.t('date.period.to'))
  content << Plasticine.localize(end_at, format: end_at_format)

  content[0].capitalize!

  return content.join(' ')
end