Class: Vitreous::Share::Indexer
- Inherits:
-
Object
- Object
- Vitreous::Share::Indexer
- Defined in:
- lib/vitreous/share/indexer.rb
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_home(structure) ⇒ Object
- #generate_not_found(structure) ⇒ Object
-
#initialize(structure) ⇒ Indexer
constructor
A new instance of Indexer.
- #json ⇒ Object
- #tree(structure) ⇒ Object
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 ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/vitreous/share/indexer.rb', line 8 def generate structure = @structure { 'home' => generate_home( structure ), 'not_found' => generate_not_found( structure ) } end |
#generate_home(structure) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vitreous/share/indexer.rb', line 17 def generate_home( structure ) { 'title' => Vitreous::Share::IndexerUtils.to_title( structure['name'] ), 'link' => '/', 'slug' => '', 'type' => 'home', 'elements' => tree( structure['elements'].select { |e| !(e['name'] =~ /^_/) }.sort { |x, y| x['name'] <=> y['name'] } ) }.merge( Vitreous::Share::IndexerUtils.( structure['elements'].select { |e| e['name'] =~ /^_home\./ } ) ) end |
#generate_not_found(structure) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vitreous/share/indexer.rb', line 31 def generate_not_found( structure ) { 'title' => 'Not found', 'type' => 'not_found', 'slug' => 'not_found', 'elements' => [], }.merge( Vitreous::Share::IndexerUtils.( structure['elements'].select { |e| e['name'] =~ /^_not_found\./ } ) ) end |
#json ⇒ Object
56 57 58 |
# File 'lib/vitreous/share/indexer.rb', line 56 def json JSON.pretty_generate( generate ) end |
#tree(structure) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vitreous/share/indexer.rb', line 44 def tree( 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'] ), 'slug' => Vitreous::Share::IndexerUtils.to_slug( e[0]['path'] ), 'type' => e.any? { |e2| e2['type'] == 'directory' } ? 'collection' : 'item', 'elements' => tree( e[0]['elements'].sort { |x, y| x['name'] <=> y['name'] } ) }.merge( Vitreous::Share::IndexerUtils.( e ) ) end end |