Class: SixSaferpay::Generators::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, mandatory = false) ⇒ Attribute

Returns a new instance of Attribute.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/models.rb', line 61

def initialize(name, type, mandatory = false)
  @name = name
  @type = type
  if mandatory == "true"
    @mandatory = true
  elsif mandatory == "false"
    @mandatory = false
  else
    @mandatory = mandatory
  end
end

Instance Attribute Details

#mandatoryObject

Returns the value of attribute mandatory.



59
60
61
# File 'lib/generators/models.rb', line 59

def mandatory
  @mandatory
end

#nameObject

Returns the value of attribute name.



59
60
61
# File 'lib/generators/models.rb', line 59

def name
  @name
end

#typeObject

Returns the value of attribute type.



59
60
61
# File 'lib/generators/models.rb', line 59

def type
  @type
end

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/generators/models.rb', line 81

def boolean?
  @type.downcase == "boolean"
end

#mandatory?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/generators/models.rb', line 73

def mandatory?
  @mandatory
end

#string?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/generators/models.rb', line 77

def string?
  @type.downcase == "string"
end

#to_hObject



89
90
91
92
93
94
95
# File 'lib/generators/models.rb', line 89

def to_h
  hash = Hash.new
  hash.merge!(name: name)
  hash.merge!(type: type)
  hash.merge!(mandatory: mandatory)
  hash
end

#to_sObject



85
86
87
# File 'lib/generators/models.rb', line 85

def to_s
  to_h
end