Class: TokyoEvents::Event

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dates, url) ⇒ Event

Returns a new instance of Event.



10
11
12
13
14
15
16
# File 'lib/tokyo_events/event.rb', line 10

def initialize(name, dates, url)
	@name = name
	@dates = dates
	@url = url

	@@all << self
end

Instance Attribute Details

#datesObject

Returns the value of attribute dates.



6
7
8
# File 'lib/tokyo_events/event.rb', line 6

def dates
  @dates
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/tokyo_events/event.rb', line 6

def description
  @description
end

#locationObject

Returns the value of attribute location.



6
7
8
# File 'lib/tokyo_events/event.rb', line 6

def location
  @location
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/tokyo_events/event.rb', line 6

def name
  @name
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/tokyo_events/event.rb', line 6

def url
  @url
end

Class Method Details

.allObject



35
36
37
# File 'lib/tokyo_events/event.rb', line 35

def self.all
	@@all
end

.find(id) ⇒ Object



39
40
41
# File 'lib/tokyo_events/event.rb', line 39

def self.find(id)
  self.all[id-1]
end

.find_by_name(name) ⇒ Object



43
44
45
46
47
# File 'lib/tokyo_events/event.rb', line 43

def self.find_by_name(name)
  self.all.select do |event|
    event.name.downcase.strip.include?(name.downcase.strip)
  end
end

.new_from_index_page(event) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/tokyo_events/event.rb', line 18

def self.new_from_index_page(event)
	self.new(
		event.css("a").text,
		event.css(".box_detail_ttl p").text,
		"https://www.gotokyo.org" + event.css("a").attribute("href").value
	)
end

Instance Method Details

#docObject



49
50
51
# File 'lib/tokyo_events/event.rb', line 49

def doc
	@doc ||= Nokogiri::HTML(open(self.url))
end