Class: Gapic::Presenters::SnippetPresenter::IterationPresenter

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

Overview

Presentation information about an iteration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proto, json) ⇒ IterationPresenter

Create an iteration presenter.

Parameters:

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

    The protobuf representation of the iteration

  • json (String)

    The JSON representation of the iteration



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 33

def initialize proto, json
  @prelude_render_lines, @postlude_render_lines =
    if json&.key? "repeatedIteration"
      parse_repeated_iteration proto.repeated_iteration, json["repeatedIteration"]
    elsif json&.key? "mapIteration"
      parse_map_iteration proto.map_iteration, json["mapIteration"]
    else
      # TODO: numeric sequence and bytes iteration
      [[], []]
    end
  if @prelude_render_lines.empty? && @postlude_render_lines.empty?
    @inner_render_lines = @render_lines = @render = nil
  else
    @inner_render_lines = parse_inner_lines proto&.statements, json&.fetch("statements", nil)
    @render_lines = @prelude_render_lines +
                    @inner_render_lines.map { |line| "  #{line}" } +
                    @postlude_render_lines
    @render = @render_lines.join "\n"
  end
end

Instance Attribute Details

#inner_render_linesArray<String> (readonly)

The inner statement lines

Returns:

  • (Array<String>)


70
71
72
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 70

def inner_render_lines
  @inner_render_lines
end

#postlude_render_linesArray<String> (readonly)

The iteration postlude lines

Returns:

  • (Array<String>)


64
65
66
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 64

def postlude_render_lines
  @postlude_render_lines
end

#prelude_render_linesArray<String> (readonly)

The iteration prelude lines

Returns:

  • (Array<String>)


58
59
60
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 58

def prelude_render_lines
  @prelude_render_lines
end

#renderString (readonly)

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

Returns:

  • (String)


82
83
84
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 82

def render
  @render
end

#render_linesArray<String> (readonly)

The lines of rendered code

Returns:

  • (Array<String>)


76
77
78
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 76

def render_lines
  @render_lines
end

Instance Method Details

#exist?Boolean

Whether the iteration could be interpreted.

Returns:

  • (Boolean)


88
89
90
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 88

def exist?
  !render_lines.nil?
end