Class: RubyMarks::ClockMark
- Inherits:
-
Object
- Object
- RubyMarks::ClockMark
- Defined in:
- lib/ruby_marks/clock_mark.rb
Instance Attribute Summary collapse
-
#coordinates ⇒ Object
Returns the value of attribute coordinates.
-
#recognizer ⇒ Object
Returns the value of attribute recognizer.
Instance Method Summary collapse
- #height ⇒ Object
- #horizontal_middle_position ⇒ Object
-
#initialize(params = {}) ⇒ ClockMark
constructor
A new instance of ClockMark.
- #invalid? ⇒ Boolean
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #vertical_middle_position ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ ClockMark
Returns a new instance of ClockMark.
8 9 10 11 12 |
# File 'lib/ruby_marks/clock_mark.rb', line 8 def initialize(params={}) params.each do |k, v| self.send("#{k}=", v) if self.respond_to?("#{k}=") end end |
Instance Attribute Details
#coordinates ⇒ Object
Returns the value of attribute coordinates.
6 7 8 |
# File 'lib/ruby_marks/clock_mark.rb', line 6 def coordinates @coordinates end |
#recognizer ⇒ Object
Returns the value of attribute recognizer.
6 7 8 |
# File 'lib/ruby_marks/clock_mark.rb', line 6 def recognizer @recognizer end |
Instance Method Details
#height ⇒ Object
45 46 47 |
# File 'lib/ruby_marks/clock_mark.rb', line 45 def height RubyMarks::ImageUtils.calc_height(@coordinates[:y1], @coordinates[:y2]) end |
#horizontal_middle_position ⇒ Object
49 50 51 |
# File 'lib/ruby_marks/clock_mark.rb', line 49 def horizontal_middle_position RubyMarks::ImageUtils.calc_middle_horizontal(@coordinates[:x1], self.width) end |
#invalid? ⇒ Boolean
37 38 39 |
# File 'lib/ruby_marks/clock_mark.rb', line 37 def invalid? !valid? end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/ruby_marks/clock_mark.rb', line 57 def to_s self.coordinates end |
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_marks/clock_mark.rb', line 14 def valid? return false if !self.recognizer.config.clock_width_tolerance_range.include?(self.width) || !self.recognizer.config.clock_height_tolerance_range.include?(self.height) x_pos = coordinates[:x1]..coordinates[:x2] y_pos = coordinates[:y1]..coordinates[:y2] colors = [] y_pos.each do |y| x_pos.each do |x| color = self.recognizer.file.pixel_color(x, y) color = RubyMarks::ImageUtils.to_hex(color.red, color.green, color.blue) color = recognizer.config.recognition_colors.include?(color) ? "." : " " colors << color end end intensity = colors.count(".") * 100 / colors.size return intensity >= 70 ? true : false end |
#vertical_middle_position ⇒ Object
53 54 55 |
# File 'lib/ruby_marks/clock_mark.rb', line 53 def vertical_middle_position RubyMarks::ImageUtils.calc_middle_vertical(@coordinates[:y1], self.height) end |
#width ⇒ Object
41 42 43 |
# File 'lib/ruby_marks/clock_mark.rb', line 41 def width RubyMarks::ImageUtils.calc_width(@coordinates[:x1], @coordinates[:x2]) end |