Class: Miam::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/miam/utils.rb

Class Method Summary collapse

Class Method Details

.bytesize(str) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/miam/utils.rb', line 11

def bytesize(str)
  if str.respond_to?(:bytesize)
    str.bytesize
  else
    str.length
  end
end

.camelize(str) ⇒ Object



7
8
9
# File 'lib/miam/utils.rb', line 7

def camelize(str)
  str.slice(0, 1).upcase + str.slice(1..-1).downcase
end

.diff(obj1, obj2, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/miam/utils.rb', line 19

def diff(obj1, obj2, options = {})
  diffy = Diffy::Diff.new(
    obj1.pretty_inspect,
    obj2.pretty_inspect,
    :diff => '-u'
  )

  out = diffy.to_s(options[:color] ? :color : :text).gsub(/\s+\z/m, '')
  out.gsub!(/^/, options[:indent]) if options[:indent]
  out
end

.unbrace(str) ⇒ Object



3
4
5
# File 'lib/miam/utils.rb', line 3

def unbrace(str)
  str.sub(/\A\s*\{/, '').sub(/\}\s*\z/, '')
end