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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/oos4ruby/bean.rb', line 36
def define_attr_reader(opts = {})
if !opts.empty?
opts.each_pair { |namespace, value|
if value.is_a?Array
value.each { |field|
define_method(field) do
name = field.to_s.gsub(/_/, '')
begin
attr = @xml.attribute(name, namespace) if @xml.instance_of? REXML::Element
return attr.value
rescue
end
end
}
elsif value.is_a?Hash
value.each_pair { |el, attr|
define_method("#{el}_#{attr}") do
el = el.to_s.gsub(/_/, '')
prefix = 'atom'
XmlNamespaces.each_pair { |name_key, name_value|
prefix = name_key if name_value.to_s == namespace.to_s
}
elem = @xml.child(el, namespace) if @xml.instance_of?Oos4ruby::Entry
elem = REXML::XPath.first(@xml, "./#{prefix}:#{el}", namespace) if @xml.instance_of?REXML::Element
if (attr.is_a?Symbol)
attr = attr.to_s.gsub(/_/, '')
begin
attr_value = elem.attribute(attr, namespace)
return attr_value.value
rescue
end
elsif attr.is_a?Hash
attr.each_pair { |attr_name, attr_namespace|
attr_name = attr_name.to_s.gsub(/_/, '')
begin
attr_value = elem.attribute(attr_name, attr_namespace)
return attr_value.value
rescue
end
}
end
end
}
end
}
end
end
|