Sha256: 8ec4aee1f632d9e02faae09e07228e21365b73b679240ad3c4552167b3b2fff9

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

module Plasticine::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 << 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

  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 'plasticine/builder/base'
require 'plasticine/builder/column'
require 'plasticine/builder/line'

Version data entries

9 entries across 9 versions & 1 rubygems

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