Module: Xml2Go
- Defined in:
- lib/xml2go.rb,
lib/xml2go/parser.rb,
lib/xml2go/struct.rb
Defined Under Namespace
Classes: Field, Parser, Struct
Class Method Summary
collapse
Class Method Details
.get_const_name(str) ⇒ Object
9
10
11
12
|
# File 'lib/xml2go.rb', line 9
def self.get_const_name(str)
final_str = ""
return str.gsub(/([A-Z])/){|c| "_#{c}"}.gsub(/^_/, "").upcase
end
|
.load(file_handle) ⇒ Object
14
15
16
17
|
# File 'lib/xml2go.rb', line 14
def self.load(file_handle)
@@doc = Nokogiri::XML(file_handle)
@@structs = {}
end
|
.parse(config) ⇒ Object
19
20
21
22
|
# File 'lib/xml2go.rb', line 19
def self.parse(config)
@@config = config
parse_element(@@doc)
end
|
.parse_element(element) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/xml2go.rb', line 24
def self.parse_element(element)
@@parser = Xml2Go::Parser.new(@@config)
@@parser.parse_element(element)
@@structs = @@parser.structs
return
end
|
.write_mocks_to_file(filename) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/xml2go.rb', line 38
def self.write_mocks_to_file(filename)
file_handle = File.new(filename, "w")
file_handle.write("package main\n\n")
consts = @@structs.values.map{ |v| v.get_consts }
file_handle.write(consts.join("\n"))
blobs = @@structs.values.map { |v| v.to_declaration}
file_handle.write(blobs.join("\n"))
file_handle.close()
end
|
.write_to_file(filename) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/xml2go.rb', line 31
def self.write_to_file(filename)
file_handle = File.new(filename, "w")
file_handle.write("package main\n\n")
file_handle.write(@@structs.values.join("\n"))
file_handle.close()
end
|