Class: Softlayer::Generator::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/softlayer/generator/converter.rb

Class Method Summary collapse

Class Method Details

.class_name(name) ⇒ Object



78
79
80
81
82
83
# File 'lib/softlayer/generator/converter.rb', line 78

def self.class_name(name)
  name.sub!(/\A(tns:)?SoftLayer_/, '')
  name.gsub!("_", "::")
  name.sub!("Network::Storage::Iscsi::OS", "Network::Storage::Iscsi::Os") if name.match(/Network::Storage::Iscsi::OS/)
  "Softlayer::" + name
end

.message_name(message) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/softlayer/generator/converter.rb', line 89

def self.message_name(message)
  return "new_getBandwidthImage" if message.to_s == "new_get_bandwidth_image"
  return "getSnapshotCapacityGb" if message.to_s == "get_snapshot_capacity_gb"
  return "getArchiveDiskUsageRatePerGb" if message.to_s == "get_archive_disk_usage_rate_per_gb"
  return "getPublicImageDiskUsageRatePerGb" if message.to_s == "get_public_image_disk_usage_rate_per_gb"
  message = message.to_s.camelcase(:lower)
  message.gsub!(/Gb\z/, 'GB')
  message
end

.module_name(softlayer_type) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/softlayer/generator/converter.rb', line 58

def self.module_name(softlayer_type)
  softlayer_type = softlayer_type.dup
  case softlayer_type
  when /\ASoftLayer_([a-zA-Z]+)/
    class_name(softlayer_type)
  when /\AMcAfee_([a-zA-Z]+)/
    class_name(softlayer_type)
  when "PortalLoginToken"
    "Softlayer::PortalLoginToken"
  else
    raise Exception.new("#{softlayer_type} is a unknown converter type")
  end
end

.process_array(name) ⇒ Object



72
73
74
75
76
# File 'lib/softlayer/generator/converter.rb', line 72

def self.process_array(name)
  name.gsub!(/Array\z/, '')
  class_name = self.class_name(name)
  "Array[#{class_name}]"
end

.to_softlayer_name(name) ⇒ Object



85
86
87
# File 'lib/softlayer/generator/converter.rb', line 85

def self.to_softlayer_name(name)
  name.to_s.sub(/\ASoftlayer::/, "SoftLayer_").gsub("::", "_")
end

.type(softlayer_type) ⇒ Object



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
# File 'lib/softlayer/generator/converter.rb', line 4

def self.type(softlayer_type)
  softlayer_type = softlayer_type.dup
  softlayer_type.gsub!(/\Axsd:/, '') if softlayer_type.match(/\Axsd:/)
  softlayer_type.gsub!(/\Atns:/, '') if softlayer_type.match(/\Atns:/)
  softlayer_type.gsub!(/\Ans1:/, '') if softlayer_type.match(/\Ans1:/)
  case softlayer_type
  when /Array\z/
    process_array(softlayer_type)
  when /\Atns:SoftLayer_([a-zA-Z]+)/
    class_name(softlayer_type)
  when /\ASoftLayer_([a-zA-Z]+)/
    class_name(softlayer_type)
  when /\AMcAfee_([a-zA-Z]+)/
    class_name(softlayer_type)
  when "boolean"
    "Boolean"
  when "unsignedLong"
    "BigDecimal"
  when "int"
    "Integer"
  when "string"
    "String"
  when "dateTime"
    "DateTime"
  when "float"
    "Float"
  when "decimal"
    "Float"
  when "unsignedInt"
    "Integer"          
  when "base64Binary"
    "Softlayer::Base64Binary"
  when "ArrayOfstring"
    "Array[String]"
  when "ArrayOfint"
    "Array[Integer]"
  when "json"
    "Softlayer::Json"
  # dummy objects
  when "authenticate"
    "authenticate"
  when "resultLimit"
    "resultLimit"
  when "totalItems"
    "totalItems"
  when "nonNegativeInteger"
    "Integer"
  when "PortalLoginToken"
    "Softlayer::PortalLoginToken"
  else
    raise Exception.new("#{softlayer_type} is a unknown converter type")
  end
end