This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'nokogiri' | |
| require 'test/unit' | |
| class TestFoo < Test::Unit::TestCase | |
| def setup | |
| @doc = Nokogiri::XML(<<-eoxml) | |
| <SIF_Message> | |
| <SIF_Ack> | |
| <SIF_Header> | |
| <SIF_SourceId>Default Server</SIF_SourceId> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Nokogiri | |
| module XML | |
| class Builder | |
| def insert_html(html) | |
| Nokogiri::HTML.fragment(html).each do |child| | |
| insert child | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Net::BufferedIO #:nodoc: | |
| alias :old_rbuf_fill :rbuf_fill | |
| def rbuf_fill | |
| if @io.respond_to?(:read_nonblock) | |
| begin | |
| @rbuf << @io.read_nonblock(65536) | |
| rescue Errno::EWOULDBLOCK | |
| if IO.select([@io], nil, nil, @read_timeout) | |
| @rbuf << @io.read_nonblock(65536) | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x.report('nokogiri:entity-extract') do | |
| N.times do | |
| doc = Nokogiri::XML(xml_content) | |
| entity = doc.at('//evriThing/entity') | |
| name = facets = properties = nil | |
| href = entity['name'] | |
| score = entity['score'].to_f | |
| id = entity['id'].to_i | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| QRTools::Camera.new(0) do |cam| | |
| loop do | |
| decoder = QRTools::Decoder.decode(cam.capture) | |
| next unless decoder.body | |
| puts decoder.body | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'nokogiri' | |
| doc = Nokogiri::XML(<<-eoxml) | |
| <stores> | |
| <store name="store a"> | |
| <book>awesome</book> | |
| <book>examples</book> | |
| <book>are</book> | |
| <book>awesome</book> | |
| </store> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'nokogiri' | |
| doc = Nokogiri::HTML('<span>浦嶌啓太</span>') | |
| doc.css('span').inner_html # => 浦嶌啓太 | |
| doc = Nokogiri::HTML('<span>浦嶌啓太</span>', nil, 'UTF-8') | |
| doc.css('span').inner_html # => 浦嶌啓太 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'nokogiri' | |
| class MyDSL | |
| def initialize &block | |
| @doc = Nokogiri::HTML(<<-eohtml) | |
| <html> | |
| <body> | |
| <a href="whatever">whatevs</a> | |
| <a id='one' href="http://tenderlovemaking.com/">tlm.com</a> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'nokogiri' | |
| doc = Nokogiri::XML(<<-eoxml) | |
| <root> | |
| <car xmlns="http://gm.com/"> | |
| <tire>Michelin Model XGV</tire> | |
| </car> | |
| <bicycle xmlns="http://schwinn.com/"> | |
| <tire>I'm a bicycle tire!</tire> | |
| </bicycle> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| doc = Nokogiri::parse(open(ARGV[0], "r:utf-8").read, nil, 'UTF-8') | |
| doc.search('a').each do |el| | |
| p el | |
| if el['href'] =~ /blah.com/ | |
| puts "HERE" | |
| end | |
| end |