<commit_before>module ROXML
  class RequiredElementMissing < Exception # :nodoc:
  end
  
  #
  # Internal base class that represents an XML - Class binding.
  #
  class XMLRef # :nodoc:
    attr_reader :opts
    delegate :required?, :array?, :accessor, :default, :wrapper, :to => :opts

    def initialize(opts, instance)
      @opts = opts
      @instance = instance
    end

    def blocks
      opts.blocks || []
    end

    def to_xml(instance)
      val = instance.__send__(accessor)
      opts.to_xml.respond_to?(:call) ? opts.to_xml.call(val) : val
    end

    def name
      opts.name_explicit? ? opts.name : conventionize(opts.name)
    end

    def xpath_name
      namespacify(name)
    end

    def value_in(xml)
      xml = XML::Node.from(xml)
      value = fetch_value(xml)
      value = default if value.nil?

      freeze(apply_blocks(value))
    end

  private
    def conventionize(what)
      convention ||= @instance.class.respond_to?(:roxml_naming_convention) && @instance.class.roxml_naming_convention
      if !what.blank? && convention.respond_to?(:call)
        URI.unescape(convention.call(URI.escape(what, /\/|::/)))
      else
        what
      end
    end

    def namespacify(what)
      if what.to_s.present? && !what.to_s.include?(':') && opts.namespace != false
        [opts.namespace, @instance.class.roxml_namespace, @default_namespace].each do |namespace|
          return opts.namespace == '*' ? "*[local-name()='#{what}']" : "#{namespace}:#{what}" if namespace
        end
      end
      what
    end

    def apply_blocks(val)
      begin
        blocks.inject(val) {|val, block| block.call(val) }
      rescue Exception => ex
        raise ex, "#{accessor}: #{ex.message}"
      end
    end<commit_msg>Add support for :name => '*', :namespace => '*'<commit_after>module ROXML
  class RequiredElementMissing < Exception # :nodoc:
  end
  
  #
  # Internal base class that represents an XML - Class binding.
  #
  class XMLRef # :nodoc:
    attr_reader :opts
    delegate :required?, :array?, :accessor, :default, :wrapper, :to => :opts

    def initialize(opts, instance)
      @opts = opts
      @instance = instance
    end

    def blocks
      opts.blocks || []
    end

    def to_xml(instance)
      val = instance.__send__(accessor)
      opts.to_xml.respond_to?(:call) ? opts.to_xml.call(val) : val
    end

    def name
      opts.name_explicit? ? opts.name : conventionize(opts.name)
    end

    def xpath_name
      namespacify(name)
    end

    def value_in(xml)
      xml = XML::Node.from(xml)
      value = fetch_value(xml)
      value = default if value.nil?

      freeze(apply_blocks(value))
    end

  private
    def conventionize(what)
      convention ||= @instance.class.respond_to?(:roxml_naming_convention) && @instance.class.roxml_naming_convention
      if !what.blank? && convention.respond_to?(:call)
        URI.unescape(convention.call(URI.escape(what, /\/|::/)))
      else
        what
      end
    end

    def namespacify(what)
      if what.to_s.present? && !what.to_s.include?(':') && opts.namespace != false
        [opts.namespace, @instance.class.roxml_namespace, @default_namespace].each do |namespace|
          return opts.namespace == '*' ? (what == '*' ? "*" : "*[local-name()='#{what}']") : "#{namespace}:#{what}" if namespace
        end
      end
      what
    end

    def apply_blocks(val)
      begin
        blocks.inject(val) {|val, block| block.call(val) }
      rescue Exception => ex
        raise ex, "#{accessor}: #{ex.message}"
      end
    end
{'fraction_non_alphanumeric': 0.13316441441441443, 'fraction_numerical': 0.0, 'mean_word_length': 2.5997973657548124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, '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': '1332471', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1139, 'n_words': 251}