Sha256: 56275c24b6062002431dd8c4a4de2bc8b6ffea42d9b8f2fe737f66289df6fc01
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
module CEML class Role < Struct.new :name, :criteria, :range, :casted # def <=>(b); b.criteria.complexity <=> criteria.complexity; end def affinity candidate, star return [-1, -1, -1 ] unless fits?(candidate, star) [ criteria.complexity, -needed, -allowed ] end def filled?; needed == 0; end def one_left?; needed == 1; end def rm(*ids); casted.delete_if{ |guy| ids.include? guy[:id] }; end def needed; [range.min - casted.size, 0].max; end def allowed; [range.max - casted.size, 0].max; end def fits?(candidate, star = nil) return false unless criteria =~ candidate return false if casted.size >= range.max return false if casted.any?{ |guy| guy[:id] == candidate[:id] } return true unless star c = criteria if c.matching return unless c.matching.all?{ |g| candidate[:matchables][g] == star[:matchables][g] } end if c.radius c_ll = Geokit::LatLng(candidate[:lat], candidate[:lng]) s_ll = Geokit::LatLng(star[:lat], star[:lng]) return unless c_ll.distance_to(s_ll, :meters) <= c.radius end if c.timewindow return unless star.ts - candidate.ts <= c.timewindow end return true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ceml-0.6.0 | lib/ceml/role.rb |