Class: InternetWisdom::Site
- Inherits:
-
Object
- Object
- InternetWisdom::Site
- Defined in:
- lib/internet_wisdom/site.rb
Instance Attribute Summary collapse
-
#cur_index ⇒ Object
readonly
Returns the value of attribute cur_index.
-
#is_random ⇒ Object
Returns the value of attribute is_random.
-
#name ⇒ Object
Returns the value of attribute name.
-
#page_index ⇒ Object
Returns the value of attribute page_index.
-
#posts ⇒ Object
Returns the value of attribute posts.
-
#refresh_method ⇒ Object
Returns the value of attribute refresh_method.
Instance Method Summary collapse
- #get_post ⇒ Object
-
#initialize(name, israndom = false) ⇒ Site
constructor
A new instance of Site.
- #refresh! ⇒ Object
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_index ⇒ Object (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_random ⇒ Object
Returns the value of attribute is_random.
3 4 5 |
# File 'lib/internet_wisdom/site.rb', line 3 def is_random @is_random end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/internet_wisdom/site.rb', line 3 def name @name end |
#page_index ⇒ Object
Returns the value of attribute page_index.
3 4 5 |
# File 'lib/internet_wisdom/site.rb', line 3 def page_index @page_index end |
#posts ⇒ Object
Returns the value of attribute posts.
3 4 5 |
# File 'lib/internet_wisdom/site.rb', line 3 def posts @posts end |
#refresh_method ⇒ Object
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_post ⇒ Object
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 |