Class: KeyAcheivementsFilter

Inherits:
Object
  • Object
show all
Defined in:
ext/position_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filter_configObject

Returns the value of attribute filter_config.



3
4
5
# File 'ext/position_filter.rb', line 3

def filter_config
  @filter_config
end

Instance Method Details

#filter_achievements(achievements) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'ext/position_filter.rb', line 5

def filter_achievements(achievements)
    counts = Hash.new
    developer_not_architect = Array.new
    filtered = achievements.select() do |a|
        if !a.tags || a.tags.empty?
            filter_config.include_untagged_achievements
        else
            a.tags.each() { |t| counts[t] = counts[t] ? counts[t] += 1 : 1 }
            developer_not_architect << a if (!a.tags.include? filter_config.primary_tag) && (a.tags.include? filter_config.alt_tag)
            if (a.tags.include? :major)
                true
            else
                ! ((a.tags & filter_config.achievement_tags).empty?)
            end
        end
    end
    if !counts[filter_config.primary_tag]
        filtered = filtered | developer_not_architect
    end
    if filtered.size < filter_config.min_achievements
        needed = filter_config.min_achievements - filtered.size()
        needed.times() { |i| filtered << achievements[i] if achievements[i] && !filtered.include?(achievements[i]) }
    elsif filtered.size > filter_config.max_achievements
        filtered = filtered.select() do |a|
            if !a.tags || a.tags.empty?
                true
            else
                !a.tags.include?(:minor)
            end
        end
    end
    filtered
end