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
|
# File 'lib/wells_fargo/schema.rb', line 15
def generate_element_files
@name_map = {}
schema do |definition|
class_name = definition.attributes['name'].value
file = File.join(ElementDir, "#{WellsFargo.underscore class_name}.rb")
puts "Writing #{class_name} => #{File.basename file}"
File.open(file, 'w') do |f|
f.write <<-EOF
module WellsFargo
class Element
class #{class_name} < WellsFargo::Element
#{(definition / 'xsd|attribute').map do |attr|
name = attr.attributes['name'].value.gsub(/\s+/, '')
@name_map[WellsFargo.underscore name] = name
name = WellsFargo.underscore name
use = attr.attributes['use']
if use && 'required' == use.value
" required_attribute :#{name}"
else
" attribute :#{name}"
end
end.join("\n")}
#{(definition / 'xsd|element').map do |element|
name = (element.attributes['ref'] || element.attributes['name']).value.gsub(/\s+/, '')
@name_map[WellsFargo.underscore name] = name
name = WellsFargo.underscore name
options = {}
limit = ((max = element.attributes['maxOccurs']) && max && max.value).to_i
options[:limit] = limit if limit > 0
options[:simple] = true if element.attributes['ref'].nil?
if {} == options
" child :#{name}"
else
" child :#{name}, :limit => #{limit}"
end
end.join("\n")}
end
end
end
EOF
end
save_name_map
end
end
|