class EventsNearby::City
City
model
Attributes
events[RW]
name[RW]
state[RW]
Public Class Methods
all()
click to toggle source
# File lib/events_nearby/city.rb, line 18 def self.all @@all end
find_by(name, state)
click to toggle source
Find city if city and state combination exist already
# File lib/events_nearby/city.rb, line 23 def self.find_by(name, state) self.all.detect{|city| city.name == name && city.state == state} end
new(name, state)
click to toggle source
# File lib/events_nearby/city.rb, line 6 def initialize(name, state) @name = name @state = state @events = [] @@all << self end
parse_city_input(city_input)
click to toggle source
Parse user city input and return name of city and state
# File lib/events_nearby/city.rb, line 28 def self.parse_city_input(city_input) data = city_input.split(/[\s,]+/) if city_input.include?(",") state = data.last.gsub(/[^0-9A-Za-z]/, '').upcase city_array = data.first data.size - 1 else city_array = data end name = city_array.collect do |item| item.gsub(/[^0-9A-Za-z]/, '').capitalize end.join(" ") {name: name, state: state} end
Public Instance Methods
add_event(event)
click to toggle source
Adds new event to city array
# File lib/events_nearby/city.rb, line 14 def add_event(event) self.events << event unless self.events.include?(event) end