Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
230 additions
and
148 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
LineLength: | ||
Max: 120 | ||
AllCops: | ||
TargetRubyVersion: 2.4 | ||
TargetRubyVersion: 2.1 | ||
Exclude: | ||
- 'spec/**/*' | ||
- 'bin/*' | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module ProxyFetcher | ||
class Document | ||
module Adapters | ||
class Abstract | ||
attr_reader :doc | ||
|
||
def initialize(doc) | ||
@doc = doc | ||
end | ||
|
||
# You can override this method in you class | ||
def xpath(selector) | ||
doc.xpath(selector) | ||
end | ||
|
||
# You can override this method in you class | ||
def css(selector) | ||
doc.css(selector) | ||
end | ||
|
||
def proxy_node | ||
::ProxyFetcher::Document::Node | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module ProxyFetcher | ||
class Document | ||
module Adapters | ||
class Nokogiri < Abstract | ||
def self.setup!(*) | ||
require 'nokogiri' | ||
end | ||
|
||
def self.parse(data) | ||
new(::Nokogiri::HTML(data)) | ||
end | ||
|
||
def proxy_node | ||
Node | ||
end | ||
|
||
class Node < ProxyFetcher::Document::Node | ||
def at_xpath(*args) | ||
self.class.new(node.at_xpath(*args)) | ||
end | ||
|
||
def at_css(*args) | ||
self.class.new(node.at_css(*args)) | ||
end | ||
|
||
def attr(*args) | ||
node.attr(*args) | ||
end | ||
|
||
def content_at(*args) | ||
clear(find(*args).content) | ||
end | ||
|
||
def content | ||
node.content | ||
end | ||
|
||
def html | ||
node.inner_html | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module ProxyFetcher | ||
class Document | ||
module Adapters | ||
class Oga < Abstract | ||
def self.setup!(*) | ||
require 'oga' | ||
end | ||
|
||
def self.parse(data) | ||
new(::Oga.parse_html(data)) | ||
end | ||
|
||
def proxy_node | ||
Node | ||
end | ||
|
||
class Node < ProxyFetcher::Document::Node | ||
def at_xpath(*args) | ||
self.class.new(node.at_xpath(*args)) | ||
end | ||
|
||
def at_css(*args) | ||
self.class.new(node.at_css(*args)) | ||
end | ||
|
||
def attr(*args) | ||
node.attribute(*args).value | ||
end | ||
|
||
def content_at(*args) | ||
clear(find(*args).content) | ||
end | ||
|
||
def content | ||
node.text | ||
end | ||
|
||
def html | ||
node.to_xml | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module ProxyFetcher | ||
class Document | ||
class Node | ||
attr_reader :node | ||
|
||
def initialize(node) | ||
@node = node | ||
end | ||
|
||
def find(selector, method = :at_xpath) | ||
self.class.new(node.public_send(method, selector)) | ||
end | ||
|
||
def content | ||
raise "#{__method__} must be implemented in descendant class!" | ||
end | ||
|
||
def html | ||
raise "#{__method__} must be implemented in descendant class!" | ||
end | ||
|
||
protected | ||
|
||
def clear(text) | ||
return if text.nil? || text.empty? | ||
|
||
text.strip.gsub(/[ \t]/i, '') | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.