Module: CfInner

Instance Method Summary collapse

Instance Method Details

#additional_indentObject



8
9
10
# File 'lib/cf_factory/base/cf_inner.rb', line 8

def additional_indent
  0
end

#generateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cf_factory/base/cf_inner.rb', line 28

def generate()
  indent = " "*additional_indent()
  @result = "#{indent}"
  @result += "#{indent}{\n"
  attributes = self.get_cf_attributes
  attributes.keys.each() {|key|
    value = attributes[key]
    @result += "#{indent}          \"#{key}\" : #{set_quotes(value)},\n"
  }
  #
  @result = @result.chomp.chomp(",")
  @result += "\n#{indent}        }"
end

#generate_nameObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cf_factory/base/cf_inner.rb', line 12

def generate_name()
  indent = " "*additional_indent()
  @result = "#{indent}"
  @result += "#{indent}{\n"
  attributes = self.get_cf_attributes
  @result += "#{indent}          \"#{@name}\" : {\n"
  attributes.keys.each() {|key|
    value = attributes[key]
    @result += "#{indent}            \"#{key}\" : #{set_quotes(value)},\n"
  }
  #
  @result = @result.chomp.chomp(",")
  @result += "\n#{indent}      }"
  @result += "\n#{indent}        }"
end

#get_cf_attributesObject

Raises:

  • (Exception)


4
5
6
# File 'lib/cf_factory/base/cf_inner.rb', line 4

def get_cf_attributes
  raise Exception.new("must be defined")
end

#set_quotes(value) ⇒ Object

Sets leading and trailing quotes



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cf_factory/base/cf_inner.rb', line 43

def set_quotes(value)
  if value.class.to_s == "String"
    if value.delete(" ").start_with?("{") || value.delete(" ").start_with?("[")
      value
    else
      "\"#{value}\""
    end
  else
    value
  end
end