Class: Gapic::Presenters::SnippetPresenter::DeclarationPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/presenters/snippet/declaration_presenter.rb

Overview

Presentation information about a declaration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proto, json) ⇒ DeclarationPresenter

Create a declaration presenter.

Parameters:

  • proto (Google::Cloud::Tools::SnippetGen::ConfigLanguage::V1::Statement::Declaration)

    The protobuf representation of the declaration

  • json (String)

    The JSON representation of the declaration



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

#descriptionString? (readonly)

The description, or nil if none

Returns:

  • (String, nil)


59
60
61
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 59

def description
  @description
end

#nameString (readonly)

The name of the variable being declared

Returns:

  • (String)


53
54
55
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 53

def name
  @name
end

#renderString (readonly)

The rendered code as a single string, possibly with line breaks

Returns:

  • (String)


71
72
73
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 71

def render
  @render
end

#render_linesArray<String> (readonly)

The lines of rendered code

Returns:

  • (Array<String>)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


85
86
87
# File 'lib/gapic/presenters/snippet/declaration_presenter.rb', line 85

def value?
  @has_value
end