Class: NycToday::Event

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

Constant Summary collapse

@@all =
[]
@@sets =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Event

Returns a new instance of Event.



7
8
9
10
11
12
# File 'lib/nyc_today/event.rb', line 7

def initialize(hash)
  hash.each do |key, value|
    self.send("#{key}=", value)
  end
  @@all << self
end

Instance Attribute Details

#event_infoObject

Returns the value of attribute event_info.



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

def event_info
  @event_info
end

Returns the value of attribute event_link.



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

def event_link
  @event_link
end

#event_typeObject

Returns the value of attribute event_type.



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

def event_type
  @event_type
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#priceObject

Returns the value of attribute price.



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

def price
  @price
end

#timeObject

Returns the value of attribute time.



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

def time
  @time
end

#time_stampObject

Returns the value of attribute time_stamp.



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

def time_stamp
  @time_stamp
end

#venueObject

Returns the value of attribute venue.



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

def venue
  @venue
end

Class Method Details

.allObject



14
15
16
# File 'lib/nyc_today/event.rb', line 14

def self.all
  @@all
end

.event_sets(input) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/nyc_today/event.rb', line 46

def self.event_sets(input)
  choice = event_types[input]
  event_group = []
  all.each do |event|
    event.event_type.downcase == choice.downcase ? event_group << event : nil
  end
  @@sets = event_group.sort_by!{|e|e.time_stamp}
  sort_events
end

.event_typesObject



26
27
28
# File 'lib/nyc_today/event.rb', line 26

def self.event_types
  all.sort_by!{|e|e.event_type.length}.collect{|event|event.event_type}.uniq!
end

.midnight_fixObject



56
57
58
59
60
61
62
# File 'lib/nyc_today/event.rb', line 56

def self.midnight_fix
  midnight = []
  @@sets.reject! do |e|
    e.time_stamp.to_s[11].to_i == 0 && e.time_stamp.to_s[12].to_i < 7 ? midnight << e : nil
  end
  midnight
end

.reformat_typesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nyc_today/event.rb', line 30

def self.reformat_types
  all.each do |event|
    if event.event_type.include?("Dj")
      event.event_type.sub!("j", "J")
    elsif event.event_type.include?("Food")
      event.event_type.insert(4, ",").insert(10, " &")
    elsif event.event_type.include?("Talks")
      event.event_type = event.event_type.insert(8, " &")
    elsif event.event_type.include?("Theatre")
      event.event_type.insert(7, " &")
    else
      event.event_type
    end
  end
end

.reset_setsObject



22
23
24
# File 'lib/nyc_today/event.rb', line 22

def self.reset_sets
  sets.clear
end

.setsObject



18
19
20
# File 'lib/nyc_today/event.rb', line 18

def self.sets
  @@sets
end

.sort_eventsObject



64
65
66
67
# File 'lib/nyc_today/event.rb', line 64

def self.sort_events
  midnight_fix.sort_by!{|e|e.time_stamp}
  @@sets = @@sets.push(*midnight_fix).each_slice(5).to_a
end