Class: EventDb::Model::Event

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/eventdb/models.rb

Instance Method Summary collapse

Instance Method Details

#current_day(today = Date.today) ⇒ Object Also known as: cur_day



16
17
18
# File 'lib/eventdb/models.rb', line 16

def current_day( today=Date.today )
  today.mjd - start_date.mjd + 1   # calculate current event day (1,2,3,etc.)
end

#date_fmt(fmt = 'long') ⇒ Object

date pretty printed (pre-formatted) as string (with weeknames)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/eventdb/models.rb', line 27

def date_fmt( fmt='long' )  #  date pretty printed (pre-formatted) as string (with weeknames)

  ## note: wday - (0-6, Sunday is zero).
  if days == 1
    buf = ''
    if fmt == 'long'
      buf << Date::ABBR_DAYNAMES[start_date.wday]
      buf << ' '
    end
    buf << Date::ABBR_MONTHNAMES[start_date.month]
    buf << '/'
    buf << start_date.day.to_s
  elsif days == 2
    buf = ''
    if fmt == 'long'
      buf << Date::ABBR_DAYNAMES[start_date.wday]
      buf << '+'
      buf << Date::ABBR_DAYNAMES[end_date.wday]
      buf << ' '
    end
    buf << Date::ABBR_MONTHNAMES[start_date.month]
    buf << '/'
    buf << start_date.day.to_s
    buf << '+'
    if start_date.month != end_date.month
      buf << Date::ABBR_MONTHNAMES[end_date.month]
      buf << '/'
    end
    buf << end_date.day.to_s
  else  ## assume multi day
    buf = ''
    if fmt == 'long'
      buf << Date::ABBR_DAYNAMES[start_date.wday]
      buf << '-'
      buf << Date::ABBR_DAYNAMES[end_date.wday]
      buf << ' '
    end
    buf << Date::ABBR_MONTHNAMES[start_date.month]
    buf << '/'
    buf << start_date.day.to_s
    buf << '-'
    if start_date.month != end_date.month
      buf << Date::ABBR_MONTHNAMES[end_date.month]
      buf << '/'
    end
    buf << end_date.day.to_s
  end

  buf
end

#diff_days(today = Date.today) ⇒ Object



21
22
23
# File 'lib/eventdb/models.rb', line 21

def diff_days( today=Date.today )
  start_date.mjd - today.mjd      # note: mjd == Modified Julian Day Number
end

#liveObject

rename to now_on/on_now/now_playing/running/etc. - why? why not??



13
# File 'lib/eventdb/models.rb', line 13

scope :live,     ->( today=Date.today ) { order('start_date').where( 'start_date <= ? AND end_date >= ?', today, today )  }

#upcomingObject

todo: auto-add today ?? - why, why not?

move order('start_date') into its own scope ??


10
# File 'lib/eventdb/models.rb', line 10

scope :upcoming, ->( today=Date.today ) { order('start_date').where( 'start_date > ?', today )  }