Class: AnnotateRb::ModelAnnotator::ColumnAnnotation::ColumnComponent
- Inherits:
-
AnnotateRb::ModelAnnotator::Components::Base
- Object
- AnnotateRb::ModelAnnotator::Components::Base
- AnnotateRb::ModelAnnotator::ColumnAnnotation::ColumnComponent
- 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
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, max_size, type, attributes) ⇒ ColumnComponent
constructor
A new instance of ColumnComponent.
- #to_default ⇒ Object
- #to_markdown ⇒ Object
- #to_rdoc ⇒ Object
- #to_yard ⇒ Object
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
#attributes ⇒ Object (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_size ⇒ Object (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 |
#name ⇒ Object (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 |
#type ⇒ Object (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_default ⇒ Object
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_markdown ⇒ Object
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_rdoc ⇒ Object
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_yard ⇒ Object
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 |