Class: InternetWisdom::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/internet_wisdom/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, israndom = false) ⇒ Site

Returns a new instance of Site.



6
7
8
9
10
# File 'lib/internet_wisdom/site.rb', line 6

def initialize(name, israndom=false)
	@name = name
	@is_random = israndom
	@cur_index = 0
end

Instance Attribute Details

#cur_indexObject (readonly)

Returns the value of attribute cur_index.



4
5
6
# File 'lib/internet_wisdom/site.rb', line 4

def cur_index
  @cur_index
end

#is_randomObject

Returns the value of attribute is_random.



3
4
5
# File 'lib/internet_wisdom/site.rb', line 3

def is_random
  @is_random
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/internet_wisdom/site.rb', line 3

def name
  @name
end

#page_indexObject

Returns the value of attribute page_index.



3
4
5
# File 'lib/internet_wisdom/site.rb', line 3

def page_index
  @page_index
end

#postsObject

Returns the value of attribute posts.



3
4
5
# File 'lib/internet_wisdom/site.rb', line 3

def posts
  @posts
end

#refresh_methodObject

Returns the value of attribute refresh_method.



3
4
5
# File 'lib/internet_wisdom/site.rb', line 3

def refresh_method
  @refresh_method
end

Instance Method Details

#get_postObject



12
13
14
15
16
17
18
# File 'lib/internet_wisdom/site.rb', line 12

def get_post
	if cur_index >= posts.length
		is_random ? refresh! : @cur_index = 0
	end
	@cur_index += 1
	posts[cur_index - 1]
end

#refresh!Object



20
21
22
23
24
25
# File 'lib/internet_wisdom/site.rb', line 20

def refresh!
	puts "#{name} is refreshing!"
	refresh_method.call(self)
	@cur_index = 0
	self
end