Class: Wadling::LexiconTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/wadling.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style_sheet = "/public/wadl") ⇒ LexiconTranslator

Returns a new instance of LexiconTranslator.



10
11
12
# File 'lib/wadling.rb', line 10

def initialize(style_sheet = "/public/wadl")
  @style_sheet = style_sheet
end

Instance Attribute Details

#style_sheetObject

Returns the value of attribute style_sheet.



8
9
10
# File 'lib/wadling.rb', line 8

def style_sheet
  @style_sheet
end

Instance Method Details



48
49
50
# File 'lib/wadling.rb', line 48

def footer
  "</wadl:application>"
end

#headerObject



32
33
34
35
36
37
38
# File 'lib/wadling.rb', line 32

def header
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \
"<?xml-stylesheet type=\"text/xsl\" href=\"#{@style_sheet}\"?>" \
"<wadl:application xmlns:wadl=\"http://wadl.dev.java.net/2009/02\"" \
"    xmlns:jr=\"http://jasperreports.sourceforge.net/xsd/jasperreport.xsd\"" \
"    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://wadl.dev.java.net/2009/02 wadl.xsd \">"
end

#resources_baseObject



40
41
42
# File 'lib/wadling.rb', line 40

def resources_base
  "<wadl:resources base=\"/\">"
end

#resources_closeObject



44
45
46
# File 'lib/wadling.rb', line 44

def resources_close
  "</wadl:resources>"
end

#translate_resources_into_wadl(resources, prefix = '') ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
# File 'lib/wadling.rb', line 26

def translate_resources_into_wadl(resources, prefix = '')
  return empty_wadl if no_resources?(resources)
  raise ArgumentError.new("A resource dictionary is expected") if resources_invalid?(resources)
  header + resources_base + translate_resources(resources, prefix) + resources_close + footer
end

#translate_resources_into_wadl_files(resources, path, prefix = '') ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wadling.rb', line 14

def translate_resources_into_wadl_files(resources, path, prefix = '')
  return empty_wadl if no_resources?(resources)
  raise ArgumentError.new("A resource dictionary is expected") if resources_invalid?(resources)
  raise ArgumentError.new("path invalid") if path_invalid?(path)
  resources.each do |r, v|
    File.open("#{path}/#{apply_prefix(v['id'], prefix)}.wadl", 'w') { |file|

      file.write(header + resources_base + translate_and_append_resource('', r, v, prefix) + resources_close + footer)
    }
  end
end