class ACTV::Event

Attributes

activityEndDate[R]
activityStartDate[R]
salesEndDate[R]
salesStartDate[R]
sales_end_date[R]
sales_start_date[R]

Public Class Methods

valid?(response) click to toggle source
# File lib/actv/event.rb, line 9
def self.valid? response
  ACTV::EventValidator.new(response).valid?
end

Public Instance Methods

course_map() click to toggle source
# File lib/actv/event.rb, line 13
def course_map
  @course_map ||= tag_by_description 'coursemap'
end
display_close_date() click to toggle source
# File lib/actv/event.rb, line 89
def display_close_date
  @display_close_date ||= begin
    val = tag_by_description 'displayclosedate'
    if val
      val.downcase == 'true'
    else
      true
    end
  end
end
Also aliased as: display_close_date?
display_close_date?()
Alias for: display_close_date
ended?()
Alias for: event_ended?
event_end_date() click to toggle source

Returns the asset's end date in UTC. This is pulled from the activityEndDate.

# File lib/actv/event.rb, line 123
def event_end_date
  Time.parse "#{activity_end_date} #{format_timezone_offset(timezone_offset)}"
end
event_ended?() click to toggle source
# File lib/actv/event.rb, line 53
def event_ended?
  if is_present? activity_end_date
    is_now_after? "#{activity_end_date.split('T').first}T23:59:59"
  end
end
Also aliased as: ended?
event_start_date() click to toggle source

Returns the asset's start date in UTC. This is pulled from the activityStartDate.

# File lib/actv/event.rb, line 117
def event_start_date
  Time.parse "#{activity_start_date} #{format_timezone_offset(timezone_offset)}"
end
image_url() click to toggle source
# File lib/actv/event.rb, line 131
def image_url
  defaultImage = 'https://www.active.com/images/events/hotrace.gif'
  image = ''

  self.assetImages.each do |i|
    if i.imageUrlAdr.downcase != defaultImage
      image = i.imageUrlAdr
      break
    end
  end

  if image.blank?
    if (self.logoUrlAdr && self.logoUrlAdr != defaultImage && self.logoUrlAdr =~ URI::regexp)
      image = self.logoUrlAdr
    end
  end
  image
end
is_event?() click to toggle source
# File lib/actv/event.rb, line 150
def is_event?
  true
end
online_registration?()
online_registration_available?() click to toggle source
# File lib/actv/event.rb, line 17
def online_registration_available?
  if is_present?(self.registrationUrlAdr)
    if is_present?(self.legacy_data) && is_present?(self.legacy_data.onlineRegistration.to_s)
      self.legacy_data.onlineRegistration.to_s.downcase == 'true'
    else
      true
    end
  else
    false
  end
end
Also aliased as: online_registration?
reg_closed?()
reg_not_open?()
reg_not_yet_open?()
reg_open?()
Alias for: registration_open?
registration_close_date() click to toggle source

Returns the asset's registration end date in UTC. This is pulled from the salesEndDate

# File lib/actv/event.rb, line 111
def registration_close_date
  Time.parse "#{authoritative_reg_end_date} UTC"
end
registration_closed?() click to toggle source
# File lib/actv/event.rb, line 37
def registration_closed?
  if online_registration_available?
    is_now_after? authoritative_reg_end_date
  else
    false
  end
end
Also aliased as: reg_closed?
registration_closing_soon?(time_in_days=3) click to toggle source
# File lib/actv/event.rb, line 74
def registration_closing_soon?(time_in_days=3)
  @reg_closing_soon ||= begin
    if online_registration_available?
      if self.sales_end_date
        if now_in_utc >= utc_time(self.sales_end_date) - time_in_days.days and
          now_in_utc < utc_time(self.end_date)
          return true
        end
      end
    end

    false
  end
end
registration_not_open?()
registration_not_yet_open?() click to toggle source
# File lib/actv/event.rb, line 45
def registration_not_yet_open?
  if online_registration_available?
    is_now_before? authoritative_reg_start_date
  else
    false
  end
end
registration_open?() click to toggle source
# File lib/actv/event.rb, line 29
def registration_open?
  if online_registration_available?
    is_now_between? authoritative_reg_start_date, authoritative_reg_end_date
  else
    false
  end
end
Also aliased as: reg_open?
registration_open_date() click to toggle source

Returns the asset's registration open date in UTC. This is pulled from the salesStartDate

# File lib/actv/event.rb, line 105
def registration_open_date
  Time.parse "#{authoritative_reg_start_date} UTC"
end
registration_opening_soon?(time_in_days=3) click to toggle source
# File lib/actv/event.rb, line 59
def registration_opening_soon?(time_in_days=3)
  @reg_open_soon ||= begin
    if online_registration_available?
      if self.sales_start_date
        if now_in_utc >= utc_time(self.sales_start_date) - time_in_days.days and
          now_in_utc < utc_time(self.sales_start_date)
          return true
        end
      end
    end

    false
  end
end
timezone_offset() click to toggle source
# File lib/actv/event.rb, line 127
def timezone_offset
  place.timezoneOffset + place.timezoneDST
end
video() click to toggle source
# File lib/actv/event.rb, line 154
def video
  self.images.detect { |i| i.video? }
end

Private Instance Methods

authoritative_reg_end_date() click to toggle source
# File lib/actv/event.rb, line 173
def authoritative_reg_end_date
  if is_present? sales_end_date
    sales_end_date
  elsif is_present? activity_end_date
    "#{activity_end_date.split('T').first}T23:59:59"
  elsif is_present? activity_start_date
    activity_start_date
  else
    "2100-12-31T23:59:59"
  end
end
authoritative_reg_start_date() click to toggle source
# File lib/actv/event.rb, line 185
def authoritative_reg_start_date
  if is_present? sales_start_date
    sales_start_date
  else
    "1970-01-01T00:00:00"
  end
end
format_timezone_offset(offset) click to toggle source

EG: -7 => “-0700”

# File lib/actv/event.rb, line 169
def format_timezone_offset(offset)
  (offset < 0 ? "-" : "") << offset.abs.to_s.rjust(2,'0') << '00'
end
is_empty?(obj) click to toggle source
# File lib/actv/event.rb, line 209
def is_empty? obj
  obj.respond_to?(:empty?) ? obj.empty? : !obj
end
is_now_after?(date_string) click to toggle source
# File lib/actv/event.rb, line 197
def is_now_after? date_string
  !is_now_before? date_string
end
is_now_before?(date_string) click to toggle source
# File lib/actv/event.rb, line 193
def is_now_before? date_string
  now_in_utc < utc_time(date_string)
end
is_now_between?(start_date_string, end_date_string) click to toggle source
# File lib/actv/event.rb, line 201
def is_now_between? start_date_string, end_date_string
  utc_time(start_date_string) < now_in_utc && now_in_utc < utc_time(end_date_string)
end
is_present?(obj) click to toggle source
# File lib/actv/event.rb, line 205
def is_present? obj
  !is_empty? obj
end
now_in_utc() click to toggle source
# File lib/actv/event.rb, line 213
def now_in_utc
  Time.now.utc
end
utc_time(time_string) click to toggle source
# File lib/actv/event.rb, line 217
def utc_time(time_string)
  return nil if time_string.nil? or time_string.empty?
  return Time.parse(time_string).utc
end