Class: HOCRBox
- Inherits:
-
Object
- Object
- HOCRBox
- Defined in:
- lib/hocr_box.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bottom ⇒ Object
readonly
Returns the value of attribute bottom.
-
#coordinates ⇒ Object
readonly
Returns the value of attribute coordinates.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #bottom_distance_to(other) ⇒ Object
- #coordinates_to_s ⇒ Object
- #enclosed_by?(other) ⇒ Boolean
- #encloses?(other) ⇒ Boolean
-
#initialize(*coordinates) ⇒ HOCRBox
constructor
A new instance of HOCRBox.
- #left_distance_to(other) ⇒ Object
- #left_of?(other) ⇒ Boolean
- #right_distance_to(other) ⇒ Object
- #right_of?(other) ⇒ Boolean
- #to_css_style(zoom = 1) ⇒ Object
- #to_image_html(options = {}) ⇒ Object
- #to_s ⇒ Object
- #top_distance_to(other) ⇒ Object
Constructor Details
#initialize(*coordinates) ⇒ HOCRBox
Returns a new instance of HOCRBox.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hocr_box.rb', line 7 def initialize(* coordinates) @left, @top, @right, @bottom = coordinates.flatten.collect { |x| x.to_i} @height = @bottom - @top @width = @right - @left @coordinates = [ @left, @top,@right, @bottom ] if left > right || top > bottom then raise " Negative dimensions of OCRBox ar not allowed. left #{@left} / right #{@right} - top #{@top} / bottom #{@bottom}" end end |
Instance Attribute Details
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom.
5 6 7 |
# File 'lib/hocr_box.rb', line 5 def bottom @bottom end |
#coordinates ⇒ Object (readonly)
Returns the value of attribute coordinates.
5 6 7 |
# File 'lib/hocr_box.rb', line 5 def coordinates @coordinates end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
5 6 7 |
# File 'lib/hocr_box.rb', line 5 def height @height end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
5 6 7 |
# File 'lib/hocr_box.rb', line 5 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
5 6 7 |
# File 'lib/hocr_box.rb', line 5 def right @right end |
#top ⇒ Object (readonly)
Returns the value of attribute top.
5 6 7 |
# File 'lib/hocr_box.rb', line 5 def top @top end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
5 6 7 |
# File 'lib/hocr_box.rb', line 5 def width @width end |
Instance Method Details
#bottom_distance_to(other) ⇒ Object
52 53 54 |
# File 'lib/hocr_box.rb', line 52 def bottom_distance_to(other) other.top_distance_to(self) end |
#coordinates_to_s ⇒ Object
60 61 62 |
# File 'lib/hocr_box.rb', line 60 def coordinates_to_s "(#{@left},#{@top})/(#{@right},#{@bottom})" end |
#enclosed_by?(other) ⇒ Boolean
28 29 30 |
# File 'lib/hocr_box.rb', line 28 def enclosed_by?(other) return other.encloses? self end |
#encloses?(other) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/hocr_box.rb', line 21 def encloses?(other) @left <= other.left and @right >= other.right and @top <= other.top and @bottom >= other.bottom end |
#left_distance_to(other) ⇒ Object
40 41 42 |
# File 'lib/hocr_box.rb', line 40 def left_distance_to(other) @left - other.right end |
#left_of?(other) ⇒ Boolean
32 33 34 |
# File 'lib/hocr_box.rb', line 32 def left_of?(other) @right < other.left end |
#right_distance_to(other) ⇒ Object
44 45 46 |
# File 'lib/hocr_box.rb', line 44 def right_distance_to(other) other.left_distance_to(self) end |
#right_of?(other) ⇒ Boolean
36 37 38 |
# File 'lib/hocr_box.rb', line 36 def right_of?(other) @left > other.right end |
#to_css_style(zoom = 1) ⇒ Object
64 65 66 |
# File 'lib/hocr_box.rb', line 64 def to_css_style(zoom = 1) "position:absolute; top:#{ @top * zoom }px; left:#{ @left * zoom }px; height:#{ @height * zoom }px; width:#{ @width * zoom }px;" end |
#to_image_html(options = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/hocr_box.rb', line 68 def to_image_html( = {}) css_class = [:css_class] || 'hocr_box' zoom = [:zoom] || 1 "<span style='#{ to_css_style(zoom) }' class='#{css_class}'></span>" end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/hocr_box.rb', line 56 def to_s coordinates_to_s end |
#top_distance_to(other) ⇒ Object
48 49 50 |
# File 'lib/hocr_box.rb', line 48 def top_distance_to(other) @top - other.bottom end |