Class: Gapic::Presenters::SnippetPresenter::IterationPresenter
- Inherits:
-
Object
- Object
- Gapic::Presenters::SnippetPresenter::IterationPresenter
- Defined in:
- lib/gapic/presenters/snippet/iteration_presenter.rb
Overview
Presentation information about an iteration
Instance Attribute Summary collapse
-
#inner_render_lines ⇒ Array<String>
readonly
The inner statement lines.
-
#postlude_render_lines ⇒ Array<String>
readonly
The iteration postlude lines.
-
#prelude_render_lines ⇒ Array<String>
readonly
The iteration prelude lines.
-
#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 iteration could be interpreted.
-
#initialize(proto, json) ⇒ IterationPresenter
constructor
Create an iteration presenter.
Constructor Details
#initialize(proto, json) ⇒ IterationPresenter
Create an iteration presenter.
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_lines ⇒ Array<String> (readonly)
The inner statement lines
70 71 72 |
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 70 def inner_render_lines @inner_render_lines end |
#postlude_render_lines ⇒ Array<String> (readonly)
The iteration postlude lines
64 65 66 |
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 64 def postlude_render_lines @postlude_render_lines end |
#prelude_render_lines ⇒ Array<String> (readonly)
The iteration prelude lines
58 59 60 |
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 58 def prelude_render_lines @prelude_render_lines end |
#render ⇒ String (readonly)
The rendered code as a single string, possibly with line breaks
82 83 84 |
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 82 def render @render end |
#render_lines ⇒ Array<String> (readonly)
The lines of rendered code
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.
88 89 90 |
# File 'lib/gapic/presenters/snippet/iteration_presenter.rb', line 88 def exist? !render_lines.nil? end |