Class: String

Inherits:
Object show all
Defined in:
lib/picolena/templates/lib/core_exts.rb,
lib/picolena/templates/lib/core_exts.rb

Overview

A PlainTextExtractor.command can be either a String, a Block or undefined.

Instance Method Summary collapse

Instance Method Details

#base26_hash(length = Picolena::HashLength) ⇒ Object

Creates a “probably unique” id with the desired length, composed only of lowercase letters.



3
4
5
# File 'lib/picolena/templates/lib/core_exts.rb', line 3

def base26_hash(length=Picolena::HashLength)
  Digest::MD5.hexdigest(self).to_i(16).to_s(26).tr('0-9a-p', 'a-z')[-length,length]
end

#dependenciesObject

For a given *nix command line, returns an Array of required commands:

>> "xls2csv SOURCE | grep -i [a-z] | sed -e 's/\"//g' -e 's/,*$//' -e 's/,/ /g'".dependencies
=> ["xls2csv", "grep", "sed"]


140
141
142
# File 'lib/picolena/templates/lib/core_exts.rb', line 140

def dependencies
  self.split(/\|\s*/).collect{|command_part| command_part.split(/ /).first}
end

#installed?Boolean

Returns true iff self is an available command on the system >> “grep”.installed?

> true

>> “sdfgsdfgsdf”.installed?

> false

Returns:

  • (Boolean)


12
13
14
# File 'lib/picolena/templates/lib/core_exts.rb', line 12

def installed?
   !IO.popen("which #{self}"){|i| i.read}.empty?
end