Module: SimplyGenius::Atmos::Utils

Extended by:
ActiveSupport::Concern, Utils
Includes:
GemLogger::LoggerSupport
Included in:
Utils
Defined in:
lib/simplygenius/atmos/utils.rb

Defined Under Namespace

Classes: SymbolizedMash

Instance Method Summary collapse

Instance Method Details

#clean_indent(str) ⇒ Object

remove leading whitespace using first non-empty line to determine how much space to remove from the rest. Skips empty lines



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simplygenius/atmos/utils.rb', line 17

def clean_indent(str)
  first = true
  first_size = 0
  str.lines.collect do |line|
    if line =~ /^(\s*)\S/ # line has at least one non-whitespace character
      if first
        first_size = Regexp.last_match(0).size
        first = false
      end
      line[(first_size - 1)..-1]
    else
      line
    end
  end.join()
end

#wrap(str) ⇒ Object

wraps to an 80 character limit by adding newlines



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/simplygenius/atmos/utils.rb', line 34

def wrap(str)
  result = ""
  count = 0
  str.each do |c|
    result << c
    if count >= 78
      result << "\n"
      count = 0
    else
      count += 1
    end
  end
  return result
end