Class: Conference
- Inherits:
-
Object
- Object
- Conference
- Includes:
- HTTParty
- Defined in:
- lib/get_freaky/conference.rb
Instance Attribute Summary collapse
-
#event_count ⇒ Object
Returns the value of attribute event_count.
-
#events ⇒ Object
Returns the value of attribute events.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #event_list ⇒ Object
-
#initialize(name, event_count, events) ⇒ Conference
constructor
A new instance of Conference.
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, event_count, events) ⇒ Conference
Returns a new instance of Conference.
6 7 8 9 10 |
# File 'lib/get_freaky/conference.rb', line 6 def initialize(name, event_count, events) self.name = name self.event_count = event_count self.events = events end |
Instance Attribute Details
#event_count ⇒ Object
Returns the value of attribute event_count.
4 5 6 |
# File 'lib/get_freaky/conference.rb', line 4 def event_count @event_count end |
#events ⇒ Object
Returns the value of attribute events.
4 5 6 |
# File 'lib/get_freaky/conference.rb', line 4 def events @events end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/get_freaky/conference.rb', line 4 def name @name end |
Class Method Details
.all ⇒ Object
28 29 30 31 |
# File 'lib/get_freaky/conference.rb', line 28 def self.all conferences = get("/conferences.json") conference_names = conferences.collect{|c| c["name"]} end |
.create_slug(title) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/get_freaky/conference.rb', line 45 def self.create_slug(title) title. downcase. # we cannot use slugify method below, one conference name has `:` char which must exist in url name (slug) gsub(/[ ._]/, "-"). gsub(/([|])/) { |match| CGI.escape(match) } end |
.find(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/get_freaky/conference.rb', line 12 def self.find(name) slug = create_slug(name) response = get("/conferences/#{slug}.json") if response.not_found? NullConference.new("No conference was found with that name") elsif response.success? self.new( response["name"], response["event_count"], response["events"] ) else raise response.status end end |
Instance Method Details
#event_list ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/get_freaky/conference.rb', line 33 def event_list if valid? events.map { |event| event["short_code"] } else "There was no conference found by that name." end end |
#valid? ⇒ Boolean
41 42 43 |
# File 'lib/get_freaky/conference.rb', line 41 def valid? true end |