class ReceiptDataExtraction::Specific_data

Public Class Methods

get_address(text) click to toggle source
# File lib/receipt_data_extraction.rb, line 28
def self.get_address(text)
    address = text.split(Name_reg)[1]
    text = text.sub!(address,"")
    address2 = text.split(Name_reg)[2]
    address = address + " " + address2
  return address
end
get_data_before_total(text) click to toggle source
# File lib/receipt_data_extraction.rb, line 67
def self.get_data_before_total(text)
    text =  text.split(Clean_text)[0]
  return text
end
get_date(text) click to toggle source
# File lib/receipt_data_extraction.rb, line 36
def self.get_date(text)
    date = text.match(Date_reg)
    date = Date.parse(date[0]).strftime("%d/%m/%Y")
  return date
end
get_products(text) click to toggle source
# File lib/receipt_data_extraction.rb, line 52
def self.get_products(text)
    text.scan(Product_reg) do |qtde, name_product, price, price_total|
        if (name_product != "") && (price != nil)
            if qtde != nil
                puts "-qtde: #{qtde}" 
            end    
                puts "-name_product: #{name_product}"
                puts "Price: #{price}"
            if price_total != nil
                puts "Price_Total: #{price_total}"
            end    
        end
    end    
end
get_shop_name(text) click to toggle source
# File lib/receipt_data_extraction.rb, line 22
def self.get_shop_name(text)
    shop_name = text.split(Name_reg).first
    text = text.sub!(shop_name, "")
  return shop_name
end
get_total(text) click to toggle source
# File lib/receipt_data_extraction.rb, line 42
def self.get_total(text)
    total = 0.00 
    text.scan(Total_reg) do |amount|
        if total < amount[0].to_f
            total = amount[0].to_f
        end
    end 
  return total
end

Public Instance Methods

remove_neg_values(text) click to toggle source

remove all discounts/cancellations

# File lib/receipt_data_extraction.rb, line 73
def remove_neg_values(text)
    text = text.gsub(Negative_values, "")
  return text
end