Class: Jekyll::PaginationTask::DefaultPaginationFilter

Inherits:
PaginationFilter show all
Defined in:
lib/jekyll-pagination-task/pagination_task.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, pager) ⇒ DefaultPaginationFilter

Returns a new instance of DefaultPaginationFilter.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 14

def initialize(site, pager)
  @filters = []
  conditions = pager["pagination_filter"] || []
  conditions.each do |condition|
    name = condition[0]
    relation = condition[1]
    if !respond_to?("check_#{relation}")
      Jekyll.logger.warn "Decteced unsupported action " + attr_action
                          + " in pager file " + pager.url

      next
    end
    parameters = condition[2]
    @filters << { "name" => name, "relation" => relation, "parameters" => parameters }
  end
end

Instance Method Details

#check_all(parameters, attr) ⇒ Object



31
32
33
34
35
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 31

def check_all(parameters, attr)
  return false if attr.nil?
  parameters.each { |parameter| return false if !attr.include?(parameter) }
  true
end

#check_any(parameters, attr) ⇒ Object



37
38
39
40
41
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 37

def check_any(parameters, attr)
  return false if attr.nil?
  parameters.each { |parameter| return true if attr.include?(parameter) }
  false
end

#check_in(parameters, attr) ⇒ Object



63
64
65
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 63

def check_in(parameters, attr)
  parameters.include?(attr)
end

#check_is(parameters, attr) ⇒ Object



55
56
57
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 55

def check_is(parameters, attr)
  parameters === attr
end

#check_is_not(parameters, attr) ⇒ Object



59
60
61
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 59

def check_is_not(parameters, attr)
  parameters != attr
end

#check_none(parameters, attr) ⇒ Object



49
50
51
52
53
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 49

def check_none(parameters, attr)
  return true if attr.nil?
  parameters.each { |parameter| return false if attr.include?(parameter) }
  true
end

#check_not_in(parameters, attr) ⇒ Object



67
68
69
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 67

def check_not_in(parameters, attr)
  !parameters.include?(attr)
end

#check_only(parameters, attr) ⇒ Object



43
44
45
46
47
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 43

def check_only(parameters, attr)
  return true if attr.nil?
  attr.each { |attribute| return false if !parameters.include?(attribute) }
  true
end

#satisfy?(page) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
# File 'lib/jekyll-pagination-task/pagination_task.rb', line 71

def satisfy?(page)
  @filters.each do |filter|
    relation = filter["relation"]
    parameters = filter["parameters"]
    attr = page[filter["name"]]
    checker = method("check_#{relation}")
    return false if !checker.call(parameters, attr)
  end
  true
end