Class: RubyMarks::Mark

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_marks/mark.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Mark

Returns a new instance of Mark.



7
8
9
10
11
# File 'lib/ruby_marks/mark.rb', line 7

def initialize(params={})
  params.each do |k, v|
    self.send("#{k}=", v) if self.respond_to?("#{k}=")
  end
end

Instance Attribute Details

#coordinatesObject

Returns the value of attribute coordinates.



5
6
7
# File 'lib/ruby_marks/mark.rb', line 5

def coordinates
  @coordinates
end

#distance_from_previousObject

Returns the value of attribute distance_from_previous.



5
6
7
# File 'lib/ruby_marks/mark.rb', line 5

def distance_from_previous
  @distance_from_previous
end

#groupObject

Returns the value of attribute group.



5
6
7
# File 'lib/ruby_marks/mark.rb', line 5

def group
  @group
end

#image_strObject

Returns the value of attribute image_str.



5
6
7
# File 'lib/ruby_marks/mark.rb', line 5

def image_str
  @image_str
end

#lineObject

Returns the value of attribute line.



5
6
7
# File 'lib/ruby_marks/mark.rb', line 5

def line
  @line
end

#positionObject

Returns the value of attribute position.



5
6
7
# File 'lib/ruby_marks/mark.rb', line 5

def position
  @position
end

Instance Method Details

#intensityObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_marks/mark.rb', line 19

def intensity
  if @image_str
    colors = []

    @image_str.each do |y|
      y.each do |x|
        colors << x
      end
    end

    intensity = colors.count(".") * 100 / colors.size
  end
end

#marked?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/ruby_marks/mark.rb', line 13

def marked?
  if @image_str
    return intensity >= @group.recognizer.config.intensity_percentual
  end
end

#unmarked?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ruby_marks/mark.rb', line 33

def unmarked?
  !marked?
end

#valueObject



37
38
39
40
41
42
43
44
# File 'lib/ruby_marks/mark.rb', line 37

def value 
  if @group
    position = @group.marks[line].index(self)
    
    values = @group.marks_options
    return position && values[position]
  end
end