dataisland 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/dataisland.rb +29 -6
  2. metadata +12 -1
data/lib/dataisland.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # file: dataisland.rb
4
+
3
5
  require 'dynarex'
4
6
  require 'rexle'
7
+ require 'rxfhelper'
8
+
5
9
 
6
10
  class DataIsland
7
11
 
@@ -9,26 +13,45 @@ class DataIsland
9
13
 
10
14
  # e.g. url = 'http://jamesrobertson.eu/index.html'
11
15
  #
12
- def initialize(url)
16
+ def initialize(location)
13
17
 
14
- useragent = {'UserAgent' => 'Dynarex dataisland to HTML converter'}
15
- html_buffer = open(url, useragent).read
16
- @html_doc = Rexle.new html_buffer
18
+ buffer, typex = RXFHelper.read(location)
19
+ @html_doc = Rexle.new(buffer)
17
20
 
18
21
  @html_doc.xpath('//script').map(&:delete)
22
+ @html_doc.xpath('//div[@datactl]').map(&:delete)
23
+ @html_doc.root.element('body').attributes.delete :onload
24
+
19
25
  h = @html_doc.element('//object').attributes
20
26
 
21
- @location_href = File.dirname(url)
22
27
 
28
+ path = { url: -> {File.dirname(location)},
29
+ file: -> {File.expand_path(File.dirname(location))},
30
+ xml: -> {File.expand_path('.')}}
31
+
32
+ @location = path[typex].call
23
33
  @html_doc.xpath("//object[@type='text/xml']").each do |x|
24
34
 
25
35
  h = x.attributes
26
- dynarex = Dynarex.new @location_href + '/' + h[:data]
27
36
 
37
+ tmp, type2 = RXFHelper.read(h[:data])
38
+
39
+ location2 = case h[:data]
40
+ when /^https?:\/\//
41
+ h[:data]
42
+ when /^\//
43
+ @location + h[:data]
44
+ else
45
+ @location +'/' + h[:data]
46
+ end
47
+
48
+ dynarex = Dynarex.new location2
49
+
28
50
  records = (h[:order] and h[:order][/^desc|descending$/]) ?
29
51
  dynarex.flat_records.reverse : dynarex.flat_records
30
52
 
31
53
  xpath = "//*[@datasrc='" + '#' + h[:id] + "']"
54
+
32
55
  @html_doc.xpath(xpath).each do |island|
33
56
  render(records, x.attributes, island.element('//*[@datafld]'));
34
57
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dataisland
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -24,6 +24,17 @@ dependencies:
24
24
  version: "0"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rxfhelper
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
27
38
  description:
28
39
  email:
29
40
  executables: []