Class: CEML::Role
- Inherits:
-
Struct
- Object
- Struct
- CEML::Role
- Defined in:
- lib/ceml/role.rb
Instance Attribute Summary collapse
-
#casted ⇒ Object
Returns the value of attribute casted.
-
#criteria ⇒ Object
Returns the value of attribute criteria.
-
#name ⇒ Object
Returns the value of attribute name.
-
#range ⇒ Object
Returns the value of attribute range.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#affinity(candidate, star) ⇒ Object
def <=>(b); b.criteria.complexity <=> criteria.complexity; end.
- #allowed ⇒ Object
- #comparable_object ⇒ Object
- #filled? ⇒ Boolean
- #fits?(candidate, star = nil) ⇒ Boolean
- #hash ⇒ Object
- #needed ⇒ Object
- #one_left? ⇒ Boolean
- #over?(star) ⇒ Boolean
- #rm(*ids) ⇒ Object
Instance Attribute Details
#casted ⇒ Object
Returns the value of attribute casted
11 12 13 |
# File 'lib/ceml/role.rb', line 11 def casted @casted end |
#criteria ⇒ Object
Returns the value of attribute criteria
11 12 13 |
# File 'lib/ceml/role.rb', line 11 def criteria @criteria end |
#name ⇒ Object
Returns the value of attribute name
11 12 13 |
# File 'lib/ceml/role.rb', line 11 def name @name end |
#range ⇒ Object
Returns the value of attribute range
11 12 13 |
# File 'lib/ceml/role.rb', line 11 def range @range end |
Instance Method Details
#==(other) ⇒ Object
22 |
# File 'lib/ceml/role.rb', line 22 def ==(other); comparable_object == other.comparable_object; end |
#affinity(candidate, star) ⇒ Object
def <=>(b); b.criteria.complexity <=> criteria.complexity; end
13 14 15 16 |
# File 'lib/ceml/role.rb', line 13 def affinity candidate, star return [-1, -1, -1 ] unless fits?(candidate, star) [ criteria.complexity, -needed, -allowed ] end |
#allowed ⇒ Object
30 |
# File 'lib/ceml/role.rb', line 30 def allowed; [range.max - casted.size, 0].max; end |
#comparable_object ⇒ Object
18 19 20 |
# File 'lib/ceml/role.rb', line 18 def comparable_object [name, criteria, range] end |
#filled? ⇒ Boolean
25 |
# File 'lib/ceml/role.rb', line 25 def filled?; needed == 0; end |
#fits?(candidate, star = nil) ⇒ Boolean
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 |
# File 'lib/ceml/role.rb', line 37 def fits?(candidate, star = nil) puts "HERE1" return false unless criteria =~ candidate puts "HERE2" return false if casted.size >= range.max puts "HERE3" return false if casted.any?{ |guy| guy[:id] == candidate[:id] } puts "HERE4" return true unless star c = criteria if c.matching puts "CEML: ATTempting to match: #{c.matching.inspect}" worked = c.matching.all? do |g| candidate[:matchables][g] && star[:matchables][g] && candidate[:matchables][g].downcase.strip == star[:matchables][g].downcase.strip end if worked puts "CEML: MATCHED" true else puts "CEML: MATCH FAILED" return false end 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 # puts "checking timewindow #{c.timewindow} #{candidate[:ts] - star[:ts]}" return unless candidate[:ts] - star[:ts] <= c.timewindow end return true end |
#hash ⇒ Object
23 |
# File 'lib/ceml/role.rb', line 23 def hash; comparable_object.hash; end |
#needed ⇒ Object
29 |
# File 'lib/ceml/role.rb', line 29 def needed; [range.min - casted.size, 0].max; end |
#one_left? ⇒ Boolean
26 |
# File 'lib/ceml/role.rb', line 26 def one_left?; needed == 1; end |
#over?(star) ⇒ Boolean
32 33 34 35 |
# File 'lib/ceml/role.rb', line 32 def over?(star) return unless criteria.timewindow and star CEML.clock - star[:ts] > criteria.timewindow end |
#rm(*ids) ⇒ Object
28 |
# File 'lib/ceml/role.rb', line 28 def rm(*ids); casted.delete_if{ |guy| ids.include? guy[:id] }; end |