Class: Accio::Content

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

Overview

Public: Represents the content of a snippet file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContent

Public: Constructor.



7
8
9
# File 'lib/accio/content.rb', line 7

def initialize
  @groups = []
end

Instance Attribute Details

#groupsObject

Returns the value of attribute groups.



4
5
6
# File 'lib/accio/content.rb', line 4

def groups
  @groups
end

Instance Method Details

#search(text, subtext = nil) ⇒ Object

Public: Search the groups and snippets for a specific text match.

text - The text for main group titles to search for. subtext - The subtext for snippet titles to search for.

Returns Array of Group matches with Snippet matches.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/accio/content.rb', line 17

def search(text, subtext = nil)
  matches  = []
  snippets = []
  @groups.each do |group|
    if group.title.downcase.include?(text.downcase)
      # Search for matches in the snippets if a subtext is given.
      if subtext
        snippets = snippets | search_snippets(group, subtext)

        # Reallocate the found snippets.
        group.snippets = snippets
      end

      matches << group
    end
  end
  matches
end