Class: Navagation

Inherits:
Object
  • Object
show all
Defined in:
lib/nytimes_cli/navagation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length) ⇒ Navagation



5
6
7
8
9
# File 'lib/nytimes_cli/navagation.rb', line 5

def initialize(length)
  @start_index = 0
  @end_index = 9
  @articles_length = length
end

Instance Attribute Details

#articles_lengthObject

Returns the value of attribute articles_length.



3
4
5
# File 'lib/nytimes_cli/navagation.rb', line 3

def articles_length
  @articles_length
end

#end_indexObject

Returns the value of attribute end_index.



3
4
5
# File 'lib/nytimes_cli/navagation.rb', line 3

def end_index
  @end_index
end

#start_indexObject

Returns the value of attribute start_index.



3
4
5
# File 'lib/nytimes_cli/navagation.rb', line 3

def start_index
  @start_index
end

Instance Method Details

#lessObject



22
23
24
25
26
27
28
29
30
# File 'lib/nytimes_cli/navagation.rb', line 22

def less
  if @start_index >= 10
    @start_index -= 10
    @end_index = @start_index + 9
  else
    @start_index = 0
    @end_index = 9
  end
end

#moreObject



12
13
14
15
16
17
18
19
20
# File 'lib/nytimes_cli/navagation.rb', line 12

def more
  if @end_index + 10 < @articles_length
    @start_index += 10
    @end_index += 10
  else
    @start_index = @articles_length - 9
    @end_index = @articles_length
  end  
end