Class: Vitreous::Share::Indexer

Inherits:
Object
  • Object
show all
Defined in:
lib/vitreous/share/indexer.rb

Instance Method Summary collapse

Constructor Details

#initialize(structure) ⇒ Indexer

Returns a new instance of Indexer.



4
5
6
# File 'lib/vitreous/share/indexer.rb', line 4

def initialize( structure )
  @structure = structure
end

Instance Method Details

#generate(structure = [@structure]) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/vitreous/share/indexer.rb', line 8

def generate( structure = [@structure] )
  Vitreous::Share::IndexerUtils.grouping( structure ).values.map do |e|
    {
      'title'    => Vitreous::Share::IndexerUtils.to_title( e[0]['name'] ),
      'link'     => Vitreous::Share::IndexerUtils.to_link( e[0]['path'] ),
      'type'     => e.any? { |e2| e2['type'] == 'directory' } ? 'collection' : 'item',
      'elements' => generate( e[0]['elements'].sort { |x, y| x['name'] <=> y['name'] } )
    }.merge( Vitreous::Share::IndexerUtils.meta_properties( e ) )
  end
end

#jsonObject



19
20
21
# File 'lib/vitreous/share/indexer.rb', line 19

def json
  JSON.pretty_generate( generate[0] )
end