code_terminator 0.4.11 → 0.4.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/code_terminator/html.rb +51 -26
- data/lib/code_terminator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 847ca2a1c19db2b0e2d79d447836878f9725b9eb
|
4
|
+
data.tar.gz: 2f1f1be2cd538ffc884d6754275201aab30af77a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1586c71b4e2cfdfeef009493894143cf6cf26caa54872b78c1ee7f380bfc26e555e9ce5aa387acc82aae33d27646d98b90a63c1253c1e706470213f5646ef173
|
7
|
+
data.tar.gz: 208ca278235f28a3a7cc854f7c3fa9391776d0bd8f9be88e901e591a5e6008a92ea903a2fa8706a8291bba9de0db80afdf33b42ce77495bd356c536c8846b655
|
data/lib/code_terminator/html.rb
CHANGED
@@ -48,49 +48,72 @@ class CodeTerminator::Html
|
|
48
48
|
|
49
49
|
def get_elements(source)
|
50
50
|
@elements = Array.new
|
51
|
+
#How to read if is an url
|
51
52
|
if @source_type == "url"
|
52
53
|
reader = Nokogiri::HTML(open(source).read)
|
53
54
|
else
|
54
55
|
reader = Nokogiri::HTML(File.open(source))
|
55
56
|
end
|
57
|
+
#remove empty spaces from reader
|
56
58
|
reader = remove_empty_text(reader)
|
59
|
+
node = Hash.new
|
60
|
+
node[:parent] = ""
|
61
|
+
node[:tag] = "html"
|
62
|
+
@elements << node
|
63
|
+
|
64
|
+
#search elements from body section
|
57
65
|
if !reader.at('body').nil?
|
66
|
+
node = Hash.new
|
67
|
+
node[:parent] = "html"
|
68
|
+
node[:tag] = "body"
|
69
|
+
@elements << node
|
70
|
+
|
58
71
|
reader.at('body').attribute_nodes.each do |element_attribute|
|
72
|
+
node = Hash.new
|
59
73
|
node[:parent] = "html"
|
60
74
|
node[:tag] = "body"
|
61
75
|
node[:attribute] = element_attribute.name if !element_attribute.name.nil?
|
62
76
|
node[:value] = element_attribute.value if !element_attribute.value.nil?
|
63
77
|
@elements << node
|
64
78
|
end
|
65
|
-
|
79
|
+
end
|
80
|
+
#end search
|
66
81
|
|
82
|
+
#search elements from head section
|
67
83
|
if !reader.at('head').nil?
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
node = Hash.new
|
85
|
+
node[:parent] = "html"
|
86
|
+
node[:tag] = "head"
|
87
|
+
@elements << node
|
88
|
+
reader.at('head').children.each do |child|
|
89
|
+
if child.attribute_nodes.empty?
|
90
|
+
node = Hash.new
|
91
|
+
node[:parent] = "head"
|
92
|
+
node[:tag] = child.name
|
93
|
+
node[:content] = child.text if !child.text.nil?
|
94
|
+
@elements << node
|
95
|
+
else
|
96
|
+
child.attribute_nodes.each do |element_attribute|
|
97
|
+
node = Hash.new
|
98
|
+
node[:parent] = "head"
|
99
|
+
if child.name == "#cdata-section"
|
100
|
+
node[:tag] = "text"
|
101
|
+
else
|
102
|
+
node[:tag] = child.name
|
103
|
+
end
|
104
|
+
# node[:tag] = ( ? "text", child.name)
|
105
|
+
node[:content] = child.text if !child.text.nil?
|
106
|
+
node[:attribute] = element_attribute.name if !element_attribute.name.nil?
|
107
|
+
node[:value] = element_attribute.value if !element_attribute.value.nil?
|
108
|
+
@elements << node
|
109
|
+
end
|
110
|
+
end
|
111
|
+
add_children(child) if child.children.any?
|
112
|
+
end
|
93
113
|
end
|
114
|
+
#end search elements
|
115
|
+
|
116
|
+
#search elements inside body (children)
|
94
117
|
if !reader.at('body').nil?
|
95
118
|
reader.at('body').children.each do |child|
|
96
119
|
if child.attribute_nodes.empty?
|
@@ -112,6 +135,8 @@ class CodeTerminator::Html
|
|
112
135
|
add_children(child) if child.children.any?
|
113
136
|
end
|
114
137
|
end
|
138
|
+
#end search elements
|
139
|
+
|
115
140
|
@elements
|
116
141
|
end
|
117
142
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_terminator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evelin Ponce
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|