Class: Fort::Type::Base

Inherits:
Object
  • Object
show all
Extended by:
Providable
Defined in:
lib/fort/type.rb

Direct Known Subclasses

Character, Logical, Numeric

Constant Summary

Constants included from Providable

Providable::ID_GENERATOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Providable

multi_provide, provide

Constructor Details

#initialize(id, params = {}) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


40
41
42
43
44
45
# File 'lib/fort/type.rb', line 40

def initialize(id, params = {})
  @id = id
  @dim = params.fetch(:dim)
  raise ArgumentError, "@dim: #{@dim}" if @dim < 0
  @type = self.class.to_s.split('::').last.to_sym
end

Instance Attribute Details

#dimObject (readonly)

Returns the value of attribute dim.



46
47
48
# File 'lib/fort/type.rb', line 46

def dim
  @dim
end

#idObject (readonly)

Returns the value of attribute id.



46
47
48
# File 'lib/fort/type.rb', line 46

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



46
47
48
# File 'lib/fort/type.rb', line 46

def type
  @type
end

Instance Method Details

#declareObject



52
53
54
# File 'lib/fort/type.rb', line 52

def declare
  "#{@type}#{dimension()}"
end

#dimensionObject



64
65
66
67
68
69
70
# File 'lib/fort/type.rb', line 64

def dimension
  if @dim >= 1
    ", dimension" + parenthesis()
  else
    ''
  end
end

#parenthesisObject



56
57
58
59
60
61
62
# File 'lib/fort/type.rb', line 56

def parenthesis
  if @dim >= 1
    "(" + colons() + ")"
  else
    ''
  end
end

#to_sObject



48
49
50
# File 'lib/fort/type.rb', line 48

def to_s
  "#{@type}Dim#{@dim}"
end