Sha256: 08e61fe41825d64f3e106d24241dcdd9874f8cf57e0a1427a80cfe649fc37020

Contents?: true

Size: 881 Bytes

Versions: 5

Compression:

Stored size: 881 Bytes

Contents

require 'sugar-high/kind_of'
require 'sugar-high/path'

class Array    
  def to_symbols option=nil
    res = self.flatten
    res.map!{|a| a.kind_of?(Fixnum) ? "_#{a}" : a} if option == :num
    res.select_labels.map(&:to_s).map(&:to_sym)
  end  

  def to_strings
    self.flatten.select_labels.map(&:to_s)
  end  

  def to_filenames
    self.to_strings.map(&:underscore)
  end  


  def to_paths
    self.map(&:path)
  end

  def file_join
    File.join(*self.flatten)
  end    

  def to_files
    self.map{|fp| fp.path.to_file }
    self.extend FilesArray    
  end
  
  def none?
    self.flatten.compact.empty?
  end 
  
 def flat_uniq
   self.flatten.compact.uniq
 end 
end

module FilesArray
  def delete_all!
    self.each do |f| 
      f.delete! if f.kind_of?(File)
    end
  end
end

class NilClass  
  def flat_uniq  
    []
  end
  
  def none?
    true
  end
end


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sugar-high-0.4.0 lib/sugar-high/array.rb
sugar-high-0.3.7 lib/sugar-high/array.rb
sugar-high-0.3.6 lib/sugar-high/array.rb
sugar-high-0.3.5 lib/sugar-high/array.rb
sugar-high-0.3.4 lib/sugar-high/array.rb