Skip to content

Commit

Permalink
uses a clearer syntax for delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeiniesta committed Nov 22, 2014
1 parent 870886b commit b28abcc
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
11 changes: 7 additions & 4 deletions lib/meta_inspector/document.rb
Expand Up @@ -37,10 +37,13 @@ def initialize(initial_url, options = {})
end

extend Forwardable
def_delegators :@url, :url, :scheme, :host, :root_url
def_delegators :@request, :content_type, :response
def_delegators :@parser, :parsed, :respond_to?, :title, :description, :links,
:images, :image, :feed, :charset, :meta_tags, :meta_tag, :meta, :favicon
delegate [:url, :scheme, :host, :root_url] => :@url

delegate [:content_type, :response] => :@request

delegate [:parsed, :title, :description, :links,
:images, :feed, :charset, :meta_tags,
:meta_tag, :meta, :favicon] => :@parser

# Returns all document data as a nested Hash
def to_hash
Expand Down
2 changes: 1 addition & 1 deletion lib/meta_inspector/exceptionable.rb
Expand Up @@ -4,6 +4,6 @@ module MetaInspector
#
module Exceptionable
extend Forwardable
def_delegators :@exception_log, :exceptions, :ok?
delegate [:exceptions, :ok?] => :@exception_log
end
end
10 changes: 5 additions & 5 deletions lib/meta_inspector/parser.rb
Expand Up @@ -20,11 +20,11 @@ def initialize(document, options = {})
end

extend Forwardable
def_delegators :@document, :url, :scheme, :host
def_delegators :@meta_tag_parser, :meta_tags, :meta_tag, :meta, :charset
def_delegators :@links_parser, :links, :feed, :base_url
def_delegators :@images_parser, :images
def_delegators :@texts_parser, :title, :description
delegate [:url, :scheme, :host] => :@document
delegate [:meta_tags, :meta_tag, :meta, :charset] => :@meta_tag_parser
delegate [:links, :feed, :base_url] => :@links_parser
delegate :images => :@images_parser
delegate [:title, :description] => :@texts_parser

# Returns the whole parsed document
def parsed
Expand Down
4 changes: 2 additions & 2 deletions lib/meta_inspector/parsers/images.rb
@@ -1,8 +1,8 @@
module MetaInspector
module Parsers
class ImagesParser < Base
def_delegators :@main_parser, :parsed, :meta, :base_url
def_delegators :images_collection, :each, :length, :size, :last, :[]
delegate [:parsed, :meta, :base_url] => :@main_parser
delegate [:each, :length, :size, :[], :last] => :images_collection

include Enumerable

Expand Down
2 changes: 1 addition & 1 deletion lib/meta_inspector/parsers/links.rb
@@ -1,7 +1,7 @@
module MetaInspector
module Parsers
class LinksParser < Base
def_delegators :@main_parser, :parsed, :url, :scheme, :host
delegate [:parsed, :url, :scheme, :host] => :@main_parser

def links
self
Expand Down
2 changes: 1 addition & 1 deletion lib/meta_inspector/parsers/meta_tags.rb
@@ -1,7 +1,7 @@
module MetaInspector
module Parsers
class MetaTagsParser < Base
def_delegators :@main_parser, :parsed
delegate :parsed => :@main_parser

def meta_tags
{
Expand Down
2 changes: 1 addition & 1 deletion lib/meta_inspector/parsers/texts.rb
@@ -1,7 +1,7 @@
module MetaInspector
module Parsers
class TextsParser < Base
def_delegators :@main_parser, :parsed, :meta
delegate [:parsed, :meta] => :@main_parser

# Returns the parsed document title, from the content of the <title> tag
# within the <head> section.
Expand Down
2 changes: 1 addition & 1 deletion lib/meta_inspector/request.rb
Expand Up @@ -22,7 +22,7 @@ def initialize(initial_url, options = {})
end

extend Forwardable
def_delegators :@url, :url
delegate :url => :@url

def read
response.body if response
Expand Down

0 comments on commit b28abcc

Please sign in to comment.