Class: Concerns::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/events.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, title = nil, tag_line = nil, date = nil, how_to_watch = nil, arena = nil, location = nil) ⇒ Events

Returns a new instance of Events.



21
22
23
24
25
26
27
28
29
30
# 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

Instance Attribute Details

#arenaObject

Returns the value of attribute arena.



2
3
4
# File 'lib/events.rb', line 2

def arena
  @arena
end

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/events.rb', line 2

def date
  @date
end

#event_fightsObject

Returns the value of attribute event_fights.



2
3
4
# File 'lib/events.rb', line 2

def event_fights
  @event_fights
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/events.rb', line 2

def id
  @id
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/events.rb', line 2

def location
  @location
end

#tag_lineObject

Returns the value of attribute tag_line.



2
3
4
# File 'lib/events.rb', line 2

def tag_line
  @tag_line
end

#timeObject

Returns the value of attribute time.



2
3
4
# File 'lib/events.rb', line 2

def time
  @time
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/events.rb', line 2

def title
  @title
end

Class Method Details

.allObject



32
33
34
# File 'lib/events.rb', line 32

def self.all
  @@all
end

.clearObject



52
53
54
# File 'lib/events.rb', line 52

def self.clear
  self.all.clear
end

.determine_location(event) ⇒ Object



42
43
44
45
# 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) ⇒ Object



47
48
49
50
# 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_eventsObject



36
37
38
39
40
# 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_from_api(events) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#clear_fightsObject



56
57
58
# File 'lib/events.rb', line 56

def clear_fights
  @event_fights.clear
end