Class: DataIsland

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, opts = {}) ⇒ DataIsland



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dataisland.rb', line 15

def initialize(location, opts={})
  
  buffer, typex = RXFHelper.read(location)
  @html_doc = Rexle.new(buffer.sub(/^<!DOCTYPE html>/,''))

  a = @html_doc.css('//script[@class="dataisland"]')
  a.map(&:delete)    

  @html_doc.xpath('//div[@datactl]').map(&:delete)
  @html_doc.root.element('body').attributes.delete :onload
  h = @html_doc.element('//object').attributes

  path = { url: -> {File.dirname(location)}, 
          file: -> {File.expand_path(File.dirname(location))}, 
           xml: -> {File.expand_path('.')}}    

  @location = path[typex].call

  @html_doc.xpath("//object[@type='text/xml']").each do |x|

    h = x.attributes
    tmp, type2 = RXFHelper.read(h[:data], opts)

    location2 = case h[:data]
      when /^https?:\/\//
        h[:data]
      when /^\//
        @location + h[:data]
      else
        @location +'/' + h[:data]
    end
    
    dynarex = Dynarex.new location2, opts      
    
    if (h[:order] and h[:order][/^desc|descending$/]) \
        or dynarex.order = 'descending' then
      #records = dynarex.flat_records.reverse
      records = dynarex.flat_records
    else
      records = dynarex.flat_records
    end

    xpath = "//*[@datasrc='" + '#' + h[:id] + "']"
    
    @html_doc.xpath(xpath).each do |island|      
      render(records, x.attributes, island.element('//*[@datafld]'));
    end
    
    x.delete unless h[:data] =~ /^\{/
  end
  
end

Instance Attribute Details

#html_docObject (readonly)

Returns the value of attribute html_doc.



11
12
13
# File 'lib/dataisland.rb', line 11

def html_doc
  @html_doc
end