Class: ODDB::Html::State::Drugs::Result::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb/html/state/drugs/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Paginator

Returns a new instance of Paginator.



16
17
18
19
20
# File 'lib/oddb/html/state/drugs/result.rb', line 16

def initialize(model)
  @model = model
  @page = 0
  @pages = [0]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args, &block) ⇒ Object



32
33
34
# File 'lib/oddb/html/state/drugs/result.rb', line 32

def method_missing(key, *args, &block)
  @model.send(key, *args, &block)
end

Instance Attribute Details

#displayObject

Returns the value of attribute display.



14
15
16
# File 'lib/oddb/html/state/drugs/result.rb', line 14

def display
  @display
end

#modelObject (readonly)

Returns the value of attribute model.



15
16
17
# File 'lib/oddb/html/state/drugs/result.rb', line 15

def model
  @model
end

#pageObject

Returns the value of attribute page.



14
15
16
# File 'lib/oddb/html/state/drugs/result.rb', line 14

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages.



15
16
17
# File 'lib/oddb/html/state/drugs/result.rb', line 15

def pages
  @pages
end

Instance Method Details

#collect!(&block) ⇒ Object



21
22
23
24
# File 'lib/oddb/html/state/drugs/result.rb', line 21

def collect!(&block)
  @model.collect!(&block)
  self
end

#each(&block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/oddb/html/state/drugs/result.rb', line 25

def each(&block)
  if(paged?)
    paged_each(&block)
  else
    @model.each(&block)
  end
end

#next_page!Object



35
36
37
38
39
# File 'lib/oddb/html/state/drugs/result.rb', line 35

def next_page!
  @page = @pages.size
  @pages.push(@model.size)
  @page
end

#overflow?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/oddb/html/state/drugs/result.rb', line 40

def overflow?
  @pages.size > 1
end

#page_countObject



43
44
45
# File 'lib/oddb/html/state/drugs/result.rb', line 43

def page_count
  @pages.size
end

#paged?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/oddb/html/state/drugs/result.rb', line 46

def paged?
  @display == 'paged'
end

#paged_each(&block) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/oddb/html/state/drugs/result.rb', line 49

def paged_each(&block)
  max = @pages.length - 1
  range = if(@page >= max) 
            @pages[max]..-1
          else
            @pages[@page]...@pages[@page.next]
          end
  @model[range].each(&block)
end

#show_details?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/oddb/html/state/drugs/result.rb', line 58

def show_details?
  !overflow? || paged?
end