class RemoteResource::DocumentWrapper

Public Instance Methods

a(attribute, selector)
Alias for: tag_attribute
abs_url(base, path) click to toggle source

abs_url('example.com', 'path?param=1')

> 'example.com/path?param=1'

abs_url('sub.domain.dev/other_path?other_param=2', 'path?param=1#anchor')

> 'sub.domain.dev/path?param=1#anchor'

# File lib/remote_resource/document_wrapper.rb, line 41
def abs_url(base, path)
  abs = URI(base)
  rel = URI(path)
  rel.scheme = abs.scheme
  rel.host   = abs.host
  rel.to_s
end
c(selector)
Alias for: css_content
c_self(selector)
Alias for: css_self_content
css_content(selector) click to toggle source
# File lib/remote_resource/document_wrapper.rb, line 2
def css_content(selector)
  selected = at_css(selector).try(:clone)
  return unless selected
  selected.css('br').each{ |br| br.replace "\n" }
  selected.try(:content).to_s.strip
end
Also aliased as: c
css_self_content(selector) click to toggle source
# File lib/remote_resource/document_wrapper.rb, line 17
def css_self_content(selector)
  at_css(selector).try(:xpath, 'text()').to_s.strip
end
Also aliased as: c_self
parse_date(date, options={}) click to toggle source
# File lib/remote_resource/document_wrapper.rb, line 23
def parse_date(date, options={})
  if options.any? && options.delete(:chronic) != false
    require 'chronic'
    Chronic.parse(date.to_s, {guess: :begin, context: :past}.merge(options))
  else
    begin
      Time.zone.parse(date.to_s)
    rescue ArgumentError
      nil
    end
  end
end
tag_attribute(attribute, selector) click to toggle source
# File lib/remote_resource/document_wrapper.rb, line 11
def tag_attribute(attribute, selector)
  at_css(selector).try(:[], attribute).to_s
end
Also aliased as: a