Sha256: c6b949e557fc738ca52309840425caa8d99052ec3541852cae37f33a58f71678

Contents?: true

Size: 701 Bytes

Versions: 2

Compression:

Stored size: 701 Bytes

Contents

module Meetupinator
  # Object passed to templates during formatting.
  class TemplateContext
    attr_reader :events

    DAY = 60 * 60 * 24

    def initialize(events)
      @events = events
    end

    # FIXME: This will probably break for daylight savings
    def get_start_of_week(d)
      d -= DAY until d.monday?
      d
    end

    def sorted_events
      events.sort { |a, b| a[:start_time] <=> b[:start_time] }
    end

    def days_list(start_date, n)
      (0..(n - 1)).map { |d| add_days(start_date, d) }
    end

    def template_binding
      binding
    end

    # FIXME: This will probably break for daylight savings
    def add_days(date, n)
      date + n * DAY
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
meetupinator-0.8.1 lib/meetupinator/template_context.rb
meetupinator-0.8 lib/meetupinator/template_context.rb