Sha256: 5dc3ae28e99581dfa2193b673d0efb7c840298c204896daa257965fed754b489

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

module ChartCandy::Builder
  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 << ChartCandy.localize(start_at, format: start_at_format)
    content << (['month', 'year'].include?(options[:step]) ? ChartCandy.t('date.period.to_month') : ChartCandy.t('date.period.to'))
    content << ChartCandy.localize(end_at, format: end_at_format)

    content[0].capitalize!

    return content.join(' ')
  end

  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
end

require 'chart-candy/builder/base.rb'
require 'chart-candy/builder/counter.rb'
require 'chart-candy/builder/donut.rb'
require 'chart-candy/builder/line.rb'
require 'chart-candy/builder/xls_builder.rb'

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
chart-candy-0.1.7 lib/chart-candy/builder.rb
chart-candy-0.1.6 lib/chart-candy/builder.rb
chart-candy-0.1.5 lib/chart-candy/builder.rb
chart-candy-0.1.4 lib/chart-candy/builder.rb
chart-candy-0.1.3 lib/chart-candy/builder.rb
chart-candy-0.1.2 lib/chart-candy/builder.rb
chart-candy-0.1.1 lib/chart-candy/builder.rb
chart-candy-0.1.0 lib/chart-candy/builder.rb
chart-candy-0.0.12 lib/chart-candy/builder.rb
chart-candy-0.0.11 lib/chart-candy/builder.rb
chart-candy-0.0.10 lib/chart-candy/builder.rb
chart-candy-0.0.9 lib/chart-candy/builder.rb
chart-candy-0.0.8 lib/chart-candy/builder.rb
chart-candy-0.0.7 lib/chart-candy/builder.rb