class HocrReader::Part
class Part
Attributes
attributes[RW]
language[RW]
part_name[RW]
text[RW]
x_end[RW]
x_start[RW]
y_end[RW]
y_start[RW]
Public Class Methods
new(part_name, phrase, title_attributes, lang)
click to toggle source
# File lib/hocr_reader/part.rb, line 11 def initialize(part_name, phrase, title_attributes, lang) @part_name = part_name[3..-2] @text = phrase.text @attributes = split_the_attributes title_attributes @x_start = bbox[0].to_i @y_start = bbox[1].to_i @x_end = bbox[2].to_i @y_end = bbox[3].to_i @language = lang end
Public Instance Methods
convert_to_parameters(attribute)
click to toggle source
# File lib/hocr_reader/part.rb, line 34 def convert_to_parameters(attribute) parameters = attribute.slice(1..-1) if parameters.length > 1 value = [] parameters.each do |parameter| value << to_numeric(parameter) end elsif numeric?(parameters[0]) value = to_numeric(parameters[0]) else value = parameters[0] end value end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/hocr_reader/part.rb, line 49 def method_missing(name, *args, &block) @attributes[name] || super end
numeric?(str)
click to toggle source
# File lib/hocr_reader/part.rb, line 69 def numeric?(str) Float(str) != nil rescue false end
respond_to_missing?(name, *)
click to toggle source
Calls superclass method
# File lib/hocr_reader/part.rb, line 53 def respond_to_missing?(name, *) if @attributes[name] else super end end
split_the_attributes(title_attributes)
click to toggle source
# File lib/hocr_reader/part.rb, line 22 def split_the_attributes(title_attributes) attributes = {} individual_attributes = [] title_attributes.each { |attrs| individual_attributes << attrs.split(' ') } # store the attibutes as keys in a hash that point to the value(s) individual_attributes.each do |attribute| key = attribute[0].to_sym attributes[key] = convert_to_parameters attribute end attributes end
to_numeric(anything)
click to toggle source
# File lib/hocr_reader/part.rb, line 60 def to_numeric(anything) num = BigDecimal(anything) if num.frac.zero? num.to_i else num.to_f end end