Class: Gapic::Presenters::SnippetPresenter::DeclarationPresenter
- Inherits:
-
Object
- Object
- Gapic::Presenters::SnippetPresenter::DeclarationPresenter
- Defined in:
- lib/gapic/presenters/snippet/declaration_presenter.rb
Overview
Presentation information about a declaration
Instance Attribute Summary collapse
-
#description ⇒ String?
readonly
The description, or nil if none.
-
#name ⇒ String
readonly
The name of the variable being declared.
-
#render ⇒ String
readonly
The rendered code as a single string, possibly with line breaks.
-
#render_lines ⇒ Array<String>
readonly
The lines of rendered code.
Instance Method Summary collapse
-
#exist? ⇒ Boolean
Whether the declaration could be interpreted.
-
#initialize(proto, json) ⇒ DeclarationPresenter
constructor
Create a declaration presenter.
-
#value? ⇒ Boolean
Whether the declaration includes a value.
Constructor Details
#initialize(proto, json) ⇒ DeclarationPresenter
Create a declaration presenter.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 33 def initialize proto, json @render = @render_lines = @name = @description = @has_value = nil return unless proto && json @name = proto.name @description = proto.description unless proto.description.empty? @render_lines = @description ? ["# #{@description}"] : [] expr = ExpressionPresenter.new proto.value, json["value"] @has_value = expr.exist? if @has_value expr_lines = expr.render_lines expr_lines[0] = "#{proto.name} = #{expr_lines.first}" @render_lines += expr_lines end @render = @render_lines.join "\n" end |
Instance Attribute Details
#description ⇒ String? (readonly)
The description, or nil if none
59 60 61 |
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 59 def description @description end |
#name ⇒ String (readonly)
The name of the variable being declared
53 54 55 |
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 53 def name @name end |
#render ⇒ String (readonly)
The rendered code as a single string, possibly with line breaks
71 72 73 |
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 71 def render @render end |
#render_lines ⇒ Array<String> (readonly)
The lines of rendered code
65 66 67 |
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 65 def render_lines @render_lines end |
Instance Method Details
#exist? ⇒ Boolean
Whether the declaration could be interpreted.
77 78 79 |
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 77 def exist? !render_lines.nil? end |
#value? ⇒ Boolean
Whether the declaration includes a value.
85 86 87 |
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 85 def value? @has_value end |