Class: String

Inherits:
Object show all
Defined in:
lib/core/string.rb

Instance Method Summary collapse

Instance Method Details

#^(h = {}) ⇒ Object



14
15
16
# File 'lib/core/string.rb', line 14

def ^(h={})
  self.gsub(/:([\w]+)/) {h[$1.to_sym] if h.include?($1.to_sym)}
end

#arrayableObject



17
18
19
# File 'lib/core/string.rb', line 17

def arrayable
  self.strip.split(/\n/)
end

#bucket_exists?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
# File 'lib/core/string.rb', line 45

def bucket_exists?
  begin
    AWS::S3::Bucket.find(self)
    return true
  rescue
    return false
  end        
end

#bucket_object(key) ⇒ Object



33
34
35
# File 'lib/core/string.rb', line 33

def bucket_object(key)
  AWS::S3::S3Object.value key, self if bucket_object_exists?(key)
end

#bucket_object_exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/core/string.rb', line 36

def bucket_object_exists?(key)
  AWS::S3::S3Object.exists? key, self
end

#bucket_objectsObject



30
31
32
# File 'lib/core/string.rb', line 30

def bucket_objects
  AWS::S3::Bucket.objects(self)
end

#classifyObject



27
28
29
# File 'lib/core/string.rb', line 27

def classify
  self.capitalize
end

#delete_bucketObject



53
54
55
# File 'lib/core/string.rb', line 53

def delete_bucket
  AWS::S3::Bucket.delete(self, :force => true) if bucket_exists?
end

#delete_bucket_value(key) ⇒ Object



42
43
44
# File 'lib/core/string.rb', line 42

def delete_bucket_value(key)
  AWS::S3::S3Object.delete(key, self) if bucket_object_exists?(key)
end

#hasherize(format = []) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/core/string.rb', line 2

def hasherize(format=[])
  hash = {}
  i = 0
  self.split(%r{[\n|\t|\s| ]+}).collect {|a| a.strip}.each do |f|
    break unless format[i]
    unless f == "" || f.nil?
      hash[format[i]] = f
      i+=1
    end      
  end
  hash
end

#nice_runnable(quite = true) ⇒ Object



24
25
26
# File 'lib/core/string.rb', line 24

def nice_runnable(quite=true)
  self.split(/ && /).join("\n")
end

#runnable(quite = true) ⇒ Object



20
21
22
23
# File 'lib/core/string.rb', line 20

def runnable(quite=true)
  # map {|l| l << "#{" >/dev/null 2>/dev/null" if quite}" }.
  self.strip.split(/\n/).join(" && ")
end

#store_bucket_value(key, data) ⇒ Object



39
40
41
# File 'lib/core/string.rb', line 39

def store_bucket_value(key, data)
  AWS::S3::S3Object.store key, data, self unless bucket_object_exists?(key)
end