-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmetadata.rb
More file actions
70 lines (61 loc) · 2.57 KB
/
metadata.rb
File metadata and controls
70 lines (61 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
67
68
69
70
module ContentstackUtils
module Model
class Metadata
def initialize( element )
if element.instance_of? Nokogiri::XML::Element
@itemType = element.attribute('type') ? element.attribute('type').value : nil
@styleType = element.attribute('sys-style-type') ? element.attribute('sys-style-type').value : nil
@itemUid ||= (element.attribute('data-sys-entry-uid') ? element.attribute('data-sys-entry-uid').value : nil) || (element.attribute('data-sys-asset-uid') ? element.attribute('data-sys-asset-uid').value : nil)
@contentTypeUid = element.attribute('data-sys-content-type-uid') ? element.attribute('data-sys-content-type-uid').value : nil
@text = element.text
@element = element
@attributes = element
else
@itemType = element["attrs"]['type']
@styleType = element["attrs"]['display-type']
@itemUid ||= element["attrs"]['entry-uid'] || element["attrs"]['asset-uid']
@contentTypeUid = element["attrs"]['content-type-uid']
if element["children"] && element["children"].length() > 0
child = element["children"]
@text = ""
for item in child do
if item["type"] == nil && item["text"]
@text += item["text"]
end
end
end
@element = element
@attributes = element["attrs"]
end
end
def item_type
@itemType ? @itemType : nil
end
def style_type
@styleType ? @styleType : nil
end
def item_uid
@itemUid ? @itemUid : nil
end
def content_type_uid
@contentTypeUid ? @contentTypeUid : nil
end
def text
@text
end
def element
@element
end
def attributes
@attributes
end
def get_attribute_value(string)
if @attributes.instance_of? Nokogiri::XML::Element
@attributes.attribute(string) ? @attributes.attribute(string).value : nil
else
@attributes[string]
end
end
end
end
end