Module: Vitreous::Share::IndexerUtils
- Defined in:
- lib/vitreous/share/indexer_utils.rb
Class Method Summary collapse
- .full_path_to_slug(path) ⇒ Object
- .grouping(elements) ⇒ Object
- .meta_arrays(meta) ⇒ Object
- .meta_properties(elements) ⇒ Object
- .remove_digits(string) ⇒ Object
- .remove_extensions(string) ⇒ Object
- .to_link(path) ⇒ Object
- .to_slug(string) ⇒ Object
- .to_title(string) ⇒ Object
Class Method Details
.full_path_to_slug(path) ⇒ Object
24 25 26 27 28 |
# File 'lib/vitreous/share/indexer_utils.rb', line 24 def self.full_path_to_slug( path ) return '' if path.empty? to_slug( remove_extensions( path.split('/').last ) ) end |
.grouping(elements) ⇒ Object
38 39 40 41 42 |
# File 'lib/vitreous/share/indexer_utils.rb', line 38 def self.grouping( elements ) elements.group_by do |e| to_slug( e['name'] ) end end |
.meta_arrays(meta) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/vitreous/share/indexer_utils.rb', line 76 def self.( ) result = {} .select { |k,v| !['meta', 'description', 'descriptions', 'file', 'files'].include? k }.each do |k,v| key = "#{k.split('_')[0]}s" result[key] ||= [] result[key] << v end result.each do |k,v| result[k].sort! end return result end |
.meta_properties(elements) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vitreous/share/indexer_utils.rb', line 44 def self.( elements ) result = {} elements.select { |e| e['type'] == 'file' }.each do |e| ext_name = File.basename( e['path'] ).split( '.' )[-1] multi_ext_name = File.basename( e['path'] ).split( '.' )[1..-1].reverse.join( '_' ) if( ext_name == 'meta' ) result[multi_ext_name] = YAML.load( e['content'] ) elsif( ext_name =~ Vitreous::TXT_EXTENSIONS ) # wildcard result['description'] ||= e['content'] result['descriptions'] ||= [] result['descriptions'] << e['content'] result[multi_ext_name] = e['content'] else # wildcard result['file'] ||= e['uri'] result['files'] ||= [] result['files'] << e['uri'] result[multi_ext_name] = e['uri'] end end # create arrays of metas result.merge!( ( result ) ) end |
.remove_digits(string) ⇒ Object
8 9 10 |
# File 'lib/vitreous/share/indexer_utils.rb', line 8 def self.remove_digits( string ) string.gsub( /^\d*[_|\s]/, '' ) end |
.remove_extensions(string) ⇒ Object
12 13 14 |
# File 'lib/vitreous/share/indexer_utils.rb', line 12 def self.remove_extensions( string ) File.basename( string ).gsub( /\..*$/, '' ) end |
.to_link(path) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/vitreous/share/indexer_utils.rb', line 16 def self.to_link( path ) return path if path == '/' path.split('/').map do |e| to_slug( remove_extensions( e ) ) end.join('/') end |
.to_slug(string) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/vitreous/share/indexer_utils.rb', line 30 def self.to_slug( string ) to_title( string ). downcase. gsub(/[^a-z0-9 \-_]/,""). gsub('_', '-'). gsub(/[ ]+/,"-") end |
.to_title(string) ⇒ Object
4 5 6 |
# File 'lib/vitreous/share/indexer_utils.rb', line 4 def self.to_title( string ) remove_digits( remove_extensions( string ) ) end |