Class: MethodParam

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

Overview


THE BEER-WARE LICENSEā€œ (Revision 42): <[email protected]> wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. Luiz Philippe.


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "", type = "", notNull = true, isObject = false, isCollection = false, isChild = false, example = nil) ⇒ MethodParam

Returns a new instance of MethodParam.



11
12
13
14
15
16
17
18
19
20
# File 'lib/phari_doc_gen/methodParam.rb', line 11

def initialize(name = "", type = "", notNull = true, isObject = false, isCollection = false, isChild = false, example = nil)
  @name = name
  @type = type
  @notNull = notNull
  @isObject = isObject
  @isCollection = isCollection
  @isChild = isChild
  @example = example
  @childAttributes = {} if (@isObject || @isCollection)
end

Instance Attribute Details

#childAttributesObject

Returns the value of attribute childAttributes.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def childAttributes
  @childAttributes
end

#exampleObject

Returns the value of attribute example.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def example
  @example
end

#isChildObject

Returns the value of attribute isChild.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def isChild
  @isChild
end

#isCollectionObject

Returns the value of attribute isCollection.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def isCollection
  @isCollection
end

#isObjectObject

Returns the value of attribute isObject.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def isObject
  @isObject
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def name
  @name
end

#notNullObject

Returns the value of attribute notNull.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def notNull
  @notNull
end

#serialObject

Returns the value of attribute serial.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def serial
  @serial
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/phari_doc_gen/methodParam.rb', line 9

def type
  @type
end

Instance Method Details

#addField(attribute) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
# File 'lib/phari_doc_gen/methodParam.rb', line 22

def addField attribute
  raise ArgumentError, "Cannot add field to no object param" unless @isObject
  @childAttributes["#{attribute.name}"] = attribute
end

#dumpObject



58
59
60
# File 'lib/phari_doc_gen/methodParam.rb', line 58

def dump
  puts self.serialize
end

#serializeObject



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/phari_doc_gen/methodParam.rb', line 32

def serialize
  if @type == 'nil'
    serialized = "Null"
  elsif @isObject
    serialized = "#{@name}: {<br><ul>"
    @childAttributes.each do |attribute|
      serialized = serialized + "<li>#{attribute[1].serialize}</li>"
    end
    serialized = serialized + "</ul>}"
  elsif @isCollection
    if @childAttributes['content'].nil?
      serialized = "#{@name}: [<br><ul><li>Null</li><li>...</li></ul>"
    else
      # puts "child attributes: #{@childAttributes['content'].type}"
      serialized = "#{@name}: [<br><ul><li>#{@childAttributes['content'].serialize},</li><li>...</li>]</ul>"
    end
  else
    unless @example.nil?
      serialized = "#{@name}: #{@example}"
    else
      serialized = "#{@name}: #{@type}"
    end
  end
  serialized
end

#setContent(attribute) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
# File 'lib/phari_doc_gen/methodParam.rb', line 27

def setContent attribute
  raise ArgumentError, "Cannot set content of no array param" unless @isCollection
  @childAttributes["content"] = attribute
end