Class: MarkdownExec::MenuBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_exec.rb

Instance Method Summary collapse

Constructor Details

#initializeMenuBuilder

Returns a new instance of MenuBuilder.



160
161
162
163
# File 'lib/markdown_exec.rb', line 160

def initialize
  @chrome_color = :cyan
  @o_color = :red
end

Instance Method Details

#build_menu(file_names, directory_names, found_in_block_names, file_name_choices, choices_from_block_names) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/markdown_exec.rb', line 165

def build_menu(file_names, directory_names, found_in_block_names,
               file_name_choices, choices_from_block_names)
  choices = []

  # Adding section title and data for file names
  choices << {
    disabled: '',
    name: AnsiString.new("in #{file_names[:section_title]}")
                    .send(@chrome_color)
  }
  choices += file_names[:data].map { |str| FileInMenu.for_menu(str) }

  # Conditionally add directory names if data is present
  if directory_names[:data].any?
    choices << {
      disabled: '',
      name: AnsiString.new("in #{directory_names[:section_title]}")
                      .send(@chrome_color)
    }
    choices += file_name_choices
  end

  # Adding found in block names
  choices << {
    disabled: '',
    name: AnsiString.new("in #{found_in_block_names[:section_title]}")
                    .send(@chrome_color)
  }
  choices += choices_from_block_names

  choices
end