1 2 3 4 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
# $Id: filter.rb 567 2006-03-09 23:46:26Z thomas $
class Filter
include Common
include Display
def initialize(data)
@waypointHash = data
end
def waypoints
@waypointHash
end
def totalWaypoints
@waypointHash.entries.length
end
def difficultyMin(num)
debug "filtering by difficultyMin: #{num}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['difficulty'] < num
}
end
def difficultyMax(num)
debug "filtering by difficultyMax: #{num}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['difficulty'] > num
}
end
def terrainMin(num)
debug "filtering by terrainMin: #{num}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['terrain'] < num
}
end
def terrainMax(num)
debug "filtering by terrainMax: #{num}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['terrain'] > num
}
end
def funFactorMin(num)
debug "filtering by funFactorMin: #{num}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['funfactor'] < num
}
end
def funFactorMax(num)
debug "filtering by funFactorMax: #{num}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['funfactor'] > num
}
end
def notFound
debug "filtering by notFound"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['mdays'].to_i > -1
}
end
def foundDateInclude(days)
debug "filtering by foundDateInclude: #{days}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['mdays'].to_i >= days.to_i
}
end
def foundDateExclude(days)
debug "filtering by foundDateExclude: #{days}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['mdays'].to_i < days.to_i
}
end
def placeDateInclude(days)
debug "filtering by placeDateInclude: #{days}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['cdays'].to_i >= days.to_i
}
end
def placeDateExclude(days)
debug "filtering by placeDateExclude: #{days}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['cdays'].to_i < days.to_i
}
end
def travelBug
debug "filtering by travelBug"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['travelbug'].to_s.length < 1
}
end
def ownerExclude(nick)
debug "filtering by ownerExclude: #{nick}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['creator'] =~ /#{nick}/i
}
end
def ownerInclude(nick)
debug "filtering by ownerInclude: #{nick}"
@waypointHash.delete_if { |wid, values|
@waypointHash[wid]['creator'] !~ /#{nick}/i
}
end
def userExclude(nick)
nick.downcase!
debug "filtering by notUser: #{nick}"
@waypointHash.each_key { |wid|
if (@waypointHash[wid]['visitors'].include?(nick))
debug " - #{nick} has visited #{@waypointHash[wid]['name']}, filtering."
@waypointHash.delete(wid)
end
}
end
def userInclude(nick)
nick.downcase!
debug "filtering by User: #{nick}"
@waypointHash.each_key { |wid|
debug "notUser #{nick}: #{wid}"
if (! @waypointHash[wid]['visitors'].include?(nick))
debug " - #{nick} has not visited #{@waypointHash[wid]['name']}, filtering."
@waypointHash.delete(wid)
end
}
end
def titleKeyword(string)
debug "filtering by title keyword: #{string}"
@waypointHash.each_key { |wid|
# I wanted to use delete_if, but I had run into a segfault in ruby 1.6.7/8
if (! (@waypointHash[wid]['name'] =~ /#{string}/i) )
@waypointHash.delete(wid)
end
}
end
def descKeyword(string)
debug "filtering by desc keyword: #{string}"
@waypointHash.each_key { |wid|
# I wanted to use delete_if, but I had run into a segfault in ruby 1.6.7/8
if (! ( (@waypointHash[wid]['details'] =~ /#{string}/i) || (@waypointHash[wid]['name'] =~ /#{string}/i)) )
@waypointHash.delete(wid)
end
}
end
def removeByElement(element)
debug "filtering by removeByElement: #{element}"
@waypointHash.each_key { |wid|
if @waypointHash[wid][element]
@waypointHash.delete(wid)
debug " - #{wid} has #{element}, filtering."
end
}
end
# add a visitor to a cache. Used by the userlookup feeder.
def addVisitor(wid, visitor)
if (@waypointHash[wid])
debug "Added visitor to #{wid}: #{visitor}"
# I don't believe we should downcase the visitors at this stage,
# since we really are losing data for the templates. I need to
# modify userInclude() and userExclude() to be case insensitive
# first.
@waypointHash[wid]['visitors'] << visitor.downcase
else
return 0
end
end
end
|