Module: Jekyll::Timeago::Core

Extended by:
Core
Included in:
Core
Defined in:
lib/jekyll-timeago/core.rb

Constant Summary collapse

MAX_DEPTH_LEVEL =

Max level of detail: years > months > weeks > days

4
DEFAULT_DEPTH_LEVEL =

Default level of detail

2
DEFAULT_THRESHOLD =

Default threshold

0
STYLES =

Available styles

%w(default short array)
ONLY_OPTIONS =

Available “only” options

%w(years months weeks days)

Instance Method Summary collapse

Instance Method Details

#timeago(from, to = Date.today, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jekyll-timeago/core.rb', line 23

def timeago(from, to = Date.today, options = {})
  if to.is_a?(Hash)
    options = to
    to = Date.today
  end

  @options = options

  @from      = validate_date(from)
  @to        = validate_date(to)
  @depth     = validate_depth(@options[:depth] || @options["depth"])
  @style     = validate_style(@options[:style] || @options["style"])
  @threshold = validate_threshold(@options[:threshold] || @options["threshold"])
  @only      = validate_only(@options[:only] || @options["only"])

  time_ago_to_now
end