Class: Namazing::Wordup

Inherits:
Object
  • Object
show all
Defined in:
lib/namazing/wordup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(boring) ⇒ Wordup

Returns a new instance of Wordup.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/namazing/wordup.rb', line 9

def initialize boring
  @boring = boring
  @awesomes = []
  raise ArgumentError, "Wordup requires a string" if @boring.class.name != "String"
end

Instance Attribute Details

#awesomes ⇒ Object

Returns the value of attribute awesomes.



7
8
9
# File 'lib/namazing/wordup.rb', line 7

def awesomes
  @awesomes
end

#boring ⇒ Object

Returns the value of attribute boring.



7
8
9
# File 'lib/namazing/wordup.rb', line 7

def boring
  @boring
end

Instance Method Details

#awesome ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/namazing/wordup.rb', line 23

def awesome
  result = @awesomes.join("_")
  if type == :camelcase
    return result.camelize(:lower)
  elsif type == :pascalcase
    return result.camelize
  end
  result
end

#split ⇒ Object



15
16
17
18
19
20
21
# File 'lib/namazing/wordup.rb', line 15

def split
  if type == :underscore
    return @boring.split("_")
  else
    return @boring.split /(?=[A-Z])/
  end
end

#type ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/namazing/wordup.rb', line 37

def type
  return :underscore if @boring =~ /_/
  if @boring =~ /[A-Z]+/
    if @boring[0] =~ /[A-Z]/
      return :pascalcase
    else
      return :camelcase
    end
  else
    return :underscore
  end
end

#word_count ⇒ Object



33
34
35
# File 'lib/namazing/wordup.rb', line 33

def word_count
  @boring.underscore.split("_").length
end