Class: JSONCop::Model::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/jsoncop/model/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Attribute

Returns a new instance of Attribute.



5
6
7
8
# File 'lib/jsoncop/model/attribute.rb', line 5

def initialize(name, type)
  @name = name.gsub(/\s+/, "")
  @type = type.gsub(/\s+/, "")
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/jsoncop/model/attribute.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/jsoncop/model/attribute.rb', line 4

def type
  @type
end

Instance Method Details

#decode_typeObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/jsoncop/model/attribute.rb', line 20

def decode_type
  built_in_types = %w[Int32 Int64 Bool Float Double]
  return real_type if built_in_types.include? real_type

  case real_type
  when "Int" then "Integer"
  when "Date" then "Object"
  else "Object"
  end
end

#optional_typeObject



15
16
17
18
# File 'lib/jsoncop/model/attribute.rb', line 15

def optional_type
  return type if type.end_with? "?"
  return type + "?"
end

#real_typeObject



10
11
12
13
# File 'lib/jsoncop/model/attribute.rb', line 10

def real_type
  return type[0..-2] if type.end_with? "?"
  return type
end