Class: Concerns::Events
- Inherits:
-
Object
- Object
- Concerns::Events
- Defined in:
- lib/events.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#arena ⇒ Object
Returns the value of attribute arena.
-
#date ⇒ Object
Returns the value of attribute date.
-
#event_fights ⇒ Object
Returns the value of attribute event_fights.
-
#id ⇒ Object
Returns the value of attribute id.
-
#location ⇒ Object
Returns the value of attribute location.
-
#tag_line ⇒ Object
Returns the value of attribute tag_line.
-
#time ⇒ Object
Returns the value of attribute time.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .all ⇒ Object
- .clear ⇒ Object
- .determine_location(event) ⇒ Object
- .fix_date(event) ⇒ Object
- .list_events ⇒ Object
- .new_from_api(events) ⇒ Object
Instance Method Summary collapse
- #clear_fights ⇒ Object
-
#initialize(id = nil, title = nil, tag_line = nil, date = nil, how_to_watch = nil, arena = nil, location = nil) ⇒ Events
constructor
A new instance of Events.
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
#arena ⇒ Object
Returns the value of attribute arena.
2 3 4 |
# File 'lib/events.rb', line 2 def arena @arena end |
#date ⇒ Object
Returns the value of attribute date.
2 3 4 |
# File 'lib/events.rb', line 2 def date @date end |
#event_fights ⇒ Object
Returns the value of attribute event_fights.
2 3 4 |
# File 'lib/events.rb', line 2 def event_fights @event_fights end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/events.rb', line 2 def id @id end |
#location ⇒ Object
Returns the value of attribute location.
2 3 4 |
# File 'lib/events.rb', line 2 def location @location end |
#tag_line ⇒ Object
Returns the value of attribute tag_line.
2 3 4 |
# File 'lib/events.rb', line 2 def tag_line @tag_line end |
#time ⇒ Object
Returns the value of attribute time.
2 3 4 |
# File 'lib/events.rb', line 2 def time @time end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/events.rb', line 2 def title @title end |
Class Method Details
.all ⇒ Object
32 33 34 |
# File 'lib/events.rb', line 32 def self.all @@all end |
.clear ⇒ Object
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_events ⇒ Object
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_fights ⇒ Object
56 57 58 |
# File 'lib/events.rb', line 56 def clear_fights @event_fights.clear end |