Sha256: 73550ecfc82539364a1e31ed17ae18c71bcc40c547a16e8a0da785bcf8ffadf8

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 KB

Contents

module Nokogiri
  module XML
    class Element
      def selector remove_id: true
        sel = name
        if !remove_id && !self['id'].nil? 
          sel = sel + '#' + self['id'].split(' ').join('#')
        end
        if !self['class'].nil?
          sel = sel + '.' + self['class'].split(' ').join('.')
        end
        attributes.select{|k,v| k != 'class' && k != 'id'}.each {
          |name, value|
          sel = sel + "[#{name}='#{value}']"
        }
        sel
      end
      def selector_and_text remove_id: true
        [selector(remove_id: remove_id), text]
      end
      alias a selector_and_text
      def child_loop
        yield self
      end
      def child_a(index)
        element_children[index].selector_and_text
      end 
      def selector_and_children remove_id: true
        [selector(remove_id: remove_id)] + children.select{|c| c.elem? || c.text.strip.size > 0}.map{|c| 
          if !c.elem? 
            c.text
          elsif c.element_children.size == 0
            c.selector_and_text remove_id: remove_id
          else
            c.selector_and_children remove_id: remove_id
          end 
        }
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
nora_mark_htmlbook-0.0.2 spec/nokogiri_test_helper.rb
nora_mark-0.2beta19 spec/nokogiri_test_helper.rb
nora_mark-0.2beta18 spec/nokogiri_test_helper.rb
nora_mark-0.2beta16 spec/nokogiri_test_helper.rb
nora_mark-0.2beta15 spec/nokogiri_test_helper.rb
nora_mark-0.2beta14 spec/nokogiri_test_helper.rb
nora_mark-0.2beta13 spec/nokogiri_test_helper.rb
nora_mark-0.2beta12 spec/nokogiri_test_helper.rb
nora_mark_htmlbook-0.0.1 spec/nokogiri_test_helper.rb
nora_mark-0.2beta11 spec/nokogiri_test_helper.rb
nora_mark-0.2beta10 spec/nokogiri_test_helper.rb
nora_mark-0.2beta9 spec/nokogiri_test_helper.rb
nora_mark-0.2beta8 spec/nokogiri_test_helper.rb
nora_mark-0.2beta7 spec/nokogiri_test_helper.rb