Class: RXFHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/rxfhelper.rb

Overview

Read XML File Helper

Class Method Summary collapse

Class Method Details

.absolute_url(page_url, item_location) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rxfhelper.rb', line 41

def self.absolute_url(page_url, item_location)

  case item_location

    when /^\//
      URL.join page_url[/https?:\/\/[^\/]+/], item_location

    when /^http/
      item_location

    else
      File.join page_url[/.*\//], item_location
  end
end

.read(x, opt = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rxfhelper.rb', line 19

def self.read(x, opt={})   
  
  if x.strip[/^</] then
    
    [x, :xml]
    
  elsif x.lines.length == 1 then
    
    if x.strip[/^https?:\/\//] then

      [open(x, 'UserAgent' => 'RXFHelper',\
        http_basic_authentication: [opt[:username], opt[:password]]).read, :url]

    elsif x[/^file:\/\//] or File.exists?(x) then
      [File.read(File.expand_path(x.sub(%r{^file://}, ''))), :file]
    end
    
  else
    [x, :unknown]
  end
end