Class: CEML::Role

Inherits:
Struct
  • Object
show all
Defined in:
lib/ceml/role.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#castedObject

Returns the value of attribute casted

Returns:

  • (Object)

    the current value of casted



11
12
13
# File 'lib/ceml/role.rb', line 11

def casted
  @casted
end

#criteriaObject

Returns the value of attribute criteria

Returns:

  • (Object)

    the current value of criteria



11
12
13
# File 'lib/ceml/role.rb', line 11

def criteria
  @criteria
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



11
12
13
# File 'lib/ceml/role.rb', line 11

def name
  @name
end

#rangeObject

Returns the value of attribute range

Returns:

  • (Object)

    the current value of 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

#allowedObject



30
# File 'lib/ceml/role.rb', line 30

def allowed; [range.max - casted.size, 0].max; end

#comparable_objectObject



18
19
20
# File 'lib/ceml/role.rb', line 18

def comparable_object
  [name, criteria, range]
end

#filled?Boolean

Returns:

  • (Boolean)


25
# File 'lib/ceml/role.rb', line 25

def filled?;   needed == 0; end

#fits?(candidate, star = nil) ⇒ Boolean

Returns:

  • (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

#hashObject



23
# File 'lib/ceml/role.rb', line 23

def hash; comparable_object.hash; end

#neededObject



29
# File 'lib/ceml/role.rb', line 29

def needed; [range.min - casted.size, 0].max; end

#one_left?Boolean

Returns:

  • (Boolean)


26
# File 'lib/ceml/role.rb', line 26

def one_left?; needed == 1; end

#over?(star) ⇒ Boolean

Returns:

  • (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