Class: AnnotateRb::ModelAnnotator::ColumnAnnotation::ColumnComponent

Inherits:
AnnotateRb::ModelAnnotator::Components::Base show all
Defined in:
lib/annotate_rb/model_annotator/column_annotation/column_component.rb

Constant Summary collapse

MD_TYPE_ALLOWANCE =
18
BARE_TYPE_ALLOWANCE =
16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, max_size, type, attributes) ⇒ ColumnComponent

Returns a new instance of ColumnComponent.



12
13
14
15
16
17
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 12

def initialize(name, max_size, type, attributes)
  @name = name
  @max_size = max_size
  @type = type
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



10
11
12
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 10

def attributes
  @attributes
end

#max_sizeObject (readonly)

Returns the value of attribute max_size.



10
11
12
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 10

def max_size
  @max_size
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 10

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 10

def type
  @type
end

Instance Method Details

#to_defaultObject



56
57
58
59
60
61
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 56

def to_default
  format("#  %s:%s %s",
    mb_chars_ljust(name, max_size),
    mb_chars_ljust(type, BARE_TYPE_ALLOWANCE),
    attributes.join(", ")).rstrip
end

#to_markdownObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 42

def to_markdown
  name_remainder = max_size - name.length - non_ascii_length(name)
  type_remainder = (MD_TYPE_ALLOWANCE - 2) - type.length

  # standard:disable Lint/FormatParameterMismatch
  format("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`",
    name,
    " ",
    type,
    " ",
    attributes.join(", ").rstrip).gsub("``", "  ").rstrip
  # standard:enable Lint/FormatParameterMismatch
end

#to_rdocObject



19
20
21
22
23
24
25
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 19

def to_rdoc
  # standard:disable Lint/FormatParameterMismatch
  format("# %-#{max_size}.#{max_size}s<tt>%s</tt>",
    "*#{name}*::",
    attributes.unshift(type).join(", ")).rstrip
  # standard:enable Lint/FormatParameterMismatch
end

#to_yardObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/annotate_rb/model_annotator/column_annotation/column_component.rb', line 27

def to_yard
  res = ""
  res += sprintf("# @!attribute #{name}") + "\n"

  ruby_class = if @column.respond_to?(:array) && @column.array
    "Array<#{map_col_type_to_ruby_classes(type)}>"
  else
    map_col_type_to_ruby_classes(type)
  end

  res += sprintf("#   @return [#{ruby_class}]")

  res
end