Sha256: 00f0d9347d3f3860f774c966721a1c57c2737cf78d072a40a144d947af7c5173

Contents?: true

Size: 618 Bytes

Versions: 8

Compression:

Stored size: 618 Bytes

Contents

require "attentive/entity"
require "date"

Attentive::Entity.define "core.date.relative.future",
    "today",
    "tomorrow",
    "{{core.date.wday}}",
    "next {{core.date.wday}}",
    published: false do |match|

  today = Date.today

  if match.matched?("core.date.wday")
    wday = match["core.date.wday"]
    days_until_wday = wday - today.wday
    days_until_wday += 7 if days_until_wday < 0
    date = today + days_until_wday

    date += 7 if match.to_s.start_with?("next")
    date
  else
    case match.to_s
    when "today" then today
    when "tomorrow" then today + 1
    else nomatch!
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
attentive-0.3.9 lib/attentive/entities/core/date/relative/future.rb
attentive-0.3.8 lib/attentive/entities/core/date/relative/future.rb
attentive-0.3.7 lib/attentive/entities/core/date/relative/future.rb
attentive-0.3.6 lib/attentive/entities/core/date/relative/future.rb
attentive-0.3.5 lib/attentive/entities/core/date/relative/future.rb
attentive-0.3.4 lib/attentive/entities/core/date/relative/future.rb
attentive-0.3.3 lib/attentive/entities/core/date/relative/future.rb
attentive-0.3.2 lib/attentive/entities/core/date/relative/future.rb