class Concerns::Events

Attributes

arena[RW]
date[RW]
event_fights[RW]
id[RW]
location[RW]
tag_line[RW]
time[RW]
title[RW]

Public Class Methods

all() click to toggle source
# File lib/events.rb, line 32
def self.all
  @@all
end
clear() click to toggle source
# File lib/events.rb, line 52
def self.clear
  self.all.clear
end
determine_location(event) click to toggle source
# File lib/events.rb, line 42
def self.determine_location(event)
  #sets location to "TBD" if location is empty
   event.location.empty? ? "TBD" : event.location
end
fix_date(event) click to toggle source
# File lib/events.rb, line 47
def self.fix_date(event)
  #parses through the event's date and changes it to a more readable format. Ex: January 19, 2019
  Time.parse(event.date).strftime("%B %d, %Y")
end
list_events() click to toggle source
# File lib/events.rb, line 36
def self.list_events
  self.all.each_with_index do |event, index|
    puts "#{index + 1}. #{event.title}: #{event.tag_line} - #{self.fix_date(event)}. #{self.determine_location(event)}."
  end
end
new(id = nil, title = nil, tag_line = nil, date = nil, how_to_watch = nil, arena = nil,location = nil) click to toggle source
# File lib/events.rb, line 21
def initialize(id = nil, title = nil, tag_line = nil, date = nil, how_to_watch = nil, arena = nil,location = nil)
  @id = id
  @title = title
  @tag_line = tag_line
  @date = date
  @how_to_watch = how_to_watch
  @location = location
  @event_fights = []
  @@all << self
end
new_from_api(events) click to toggle source
# File lib/events.rb, line 6
def self.new_from_api(events)
  #parses future and past ufc events and only creates objects of events that are happening in the future
  if Time.parse(events["event_date"]) >= Time.now == true
    self.new(
      events["id"],
      events["base_title"],
      events["title_tag_line"],
      events["event_date"],
      events["subtitle"],
      events["arena"],
      events["location"]
    )
  end
end

Public Instance Methods

clear_fights() click to toggle source
# File lib/events.rb, line 56
def clear_fights
  @event_fights.clear
end