Class: DerivativeRodeo::Services::ExtractWordCoordinatesFromHocrSgmlService::WordCoordinates
- Inherits:
-
Object
- Object
- DerivativeRodeo::Services::ExtractWordCoordinatesFromHocrSgmlService::WordCoordinates
- Defined in:
- lib/derivative_rodeo/services/extract_word_coordinates_from_hocr_sgml_service.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Class Method Summary collapse
-
.to_json(words:, width: nil, height: nil) ⇒ String
A JSON encoded string.
Instance Method Summary collapse
-
#initialize(words:, width:, height:) ⇒ WordCoordinates
constructor
A new instance of WordCoordinates.
-
#to_json ⇒ String
Output JSON flattened word coordinates.
Constructor Details
#initialize(words:, width:, height:) ⇒ WordCoordinates
Returns a new instance of WordCoordinates.
210 211 212 213 214 |
# File 'lib/derivative_rodeo/services/extract_word_coordinates_from_hocr_sgml_service.rb', line 210 def initialize(words:, width:, height:) @words = words @width = width @height = height end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
215 216 217 |
# File 'lib/derivative_rodeo/services/extract_word_coordinates_from_hocr_sgml_service.rb', line 215 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
215 216 217 |
# File 'lib/derivative_rodeo/services/extract_word_coordinates_from_hocr_sgml_service.rb', line 215 def width @width end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
215 216 217 |
# File 'lib/derivative_rodeo/services/extract_word_coordinates_from_hocr_sgml_service.rb', line 215 def words @words end |
Class Method Details
.to_json(words:, width: nil, height: nil) ⇒ String
Returns a JSON encoded string.
206 207 208 |
# File 'lib/derivative_rodeo/services/extract_word_coordinates_from_hocr_sgml_service.rb', line 206 def self.to_json(words:, width: nil, height: nil) new(words: words, width: width, height: height).to_json end |
Instance Method Details
#to_json ⇒ String
Output JSON flattened word coordinates
220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/derivative_rodeo/services/extract_word_coordinates_from_hocr_sgml_service.rb', line 220 def to_json coordinates = {} words.each do |word| word_chars = word[:word] word_coords = word[:coordinates] if coordinates[word_chars] coordinates[word_chars] << word_coords else coordinates[word_chars] = [word_coords] end end payload = { width: width, height: height, coords: coordinates } JSON.generate(payload) end |