<commit_before>class BeerXML < Brewser::Engine
  
  require 'nokogiri'

  class << self
    
    # Simple test to see if this looks like XML
    def acceptable?(q)
      Nokogiri::XML(q){|config| config.noblanks }.root ? true : false
    end
    
    # Attempt to deserialize the data
    def deserialize(string_or_io)
      begin
        outer = Nokogiri::XML(string_or_io).root
        # We expect to find a plural of one of the models
        objects = (outer>outer.node_name.singularize).map do |inner|
          ("BeerXML::#{inner.node_name.downcase.camelcase}".constantize).from_xml(inner)
        end
        return cleanup(objects)
     rescue
       raise "Brewser: BeerXML encountered an issue and can not continue"
      end
    end
    
    # Ugly hack to deal with BeerXML oddities
    def cleanup(brewser_objects)
      brewser_objects.each(&:cleanup)
    end
 
  end
end

require 'roxml'

#
#
# These models add the hooks to deserialize the data using ROXML
#  Brought in as a seperate model to allow multiple version of BeerXML
class BeerXML::Hop < Brewser::Hop
  include ROXML
  
  xml_name "HOP"
  xml_convention :upcase
  xml_reader :name
  xml_reader :origin
  xml_reader :description, :from => "NOTES"
  
  xml_reader :type
  xml_reader :form
  
  xml_reader :display_amount
  xml_reader :uncast_amount, :from => "AMOUNT"
  
  xml_reader :display_time
  xml_reader :uncast_time, :from => "TIME"
  
  xml_reader :added_when, :from => "USE"
  
  xml_reader :alpha_acids, :from => "ALPHA", :as => Float
  xml_reader :beta_acids, :from => "BETA", :as => Float
  
  xml_reader :humulene, :as => Float
  xml_reader :caryophyllene, :as => Float
  xml_reader :cohumulone, :as => Float
  xml_reader :myrcene, :as => Float<commit_msg>Translate form and added when<commit_after>class BeerXML < Brewser::Engine
  
  require 'nokogiri'

  class << self
    
    # Simple test to see if this looks like XML
    def acceptable?(q)
      Nokogiri::XML(q){|config| config.noblanks }.root ? true : false
    end
    
    # Attempt to deserialize the data
    def deserialize(string_or_io)
      begin
        outer = Nokogiri::XML(string_or_io).root
        # We expect to find a plural of one of the models
        objects = (outer>outer.node_name.singularize).map do |inner|
          ("BeerXML::#{inner.node_name.downcase.camelcase}".constantize).from_xml(inner)
        end
        return cleanup(objects)
     rescue
       raise "Brewser: BeerXML encountered an issue and can not continue"
      end
    end
    
    # Ugly hack to deal with BeerXML oddities
    def cleanup(brewser_objects)
      brewser_objects.each(&:cleanup)
    end
 
  end
end

require 'roxml'

#
#
# These models add the hooks to deserialize the data using ROXML
#  Brought in as a seperate model to allow multiple version of BeerXML
class BeerXML::Hop < Brewser::Hop
  include ROXML
  
  xml_name "HOP"
  xml_convention :upcase
  xml_reader :name
  xml_reader :origin
  xml_reader :description, :from => "NOTES"
  
  xml_reader :type
  xml_reader(:form) { |x| 
    x="Whole" if x=="Leaf"
    x
  }
  
  xml_reader :display_amount
  xml_reader :uncast_amount, :from => "AMOUNT"
  
  xml_reader :display_time
  xml_reader :uncast_time, :from => "TIME"
  
  xml_reader(:added_when, :from => "USE") { |x|
    x="Dry" if x=="Dry Hop"
    x="FWH" if x=="First Wort"
    x
    }
  
  xml_reader :alpha_acids, :from => "ALPHA", :as => Float
  xml_reader :beta_acids, :from => "BETA", :as => Float
  
  xml_reader :humulene, :as => Float
  xml_reader :caryophyllene, :as => Float
  xml_reader :cohumulone, :as => Float
  xml_reader :myrcene, :as => Float
{'fraction_non_alphanumeric': 0.09947643979057591, 'fraction_numerical': 0.0, 'mean_word_length': 3.1016949152542375, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 40}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4867511', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1241, 'n_words': 354}