Class: String::Words

Inherits:
Array
  • Object
show all
Defined in:
lib/activefacts/support.rb

Instance Method Summary collapse

Methods inherited from Array

#__orig_index, #duplicates, #elide_repeated_subsequences, #index

Instance Method Details

#+(words) ⇒ Object



127
128
129
# File 'lib/activefacts/support.rb', line 127

def +(words)
  Words.new(self + Array(words))
end

#camelcaseObject



99
100
101
# File 'lib/activefacts/support.rb', line 99

def camelcase
  camelwords.join('')
end

#camelwordsObject



88
89
90
91
92
93
94
95
96
97
# File 'lib/activefacts/support.rb', line 88

def camelwords
  count = 0
  map do |word|
    if (count += 1) == 1
      word.downcase   # The camel has his head down
    else
      word[0].upcase+word[1..-1].downcase
    end
  end
end

#capcaseObject



84
85
86
# File 'lib/activefacts/support.rb', line 84

def capcase
  capwords.join('')
end

#capwordsObject



78
79
80
81
82
# File 'lib/activefacts/support.rb', line 78

def capwords
  map do |word|
    word[0].upcase+word[1..-1]
  end
end

#inspectObject



60
61
62
# File 'lib/activefacts/support.rb', line 60

def inspect
  'Words'+super
end

#shoutcase(joiner = '_') ⇒ Object



119
120
121
# File 'lib/activefacts/support.rb', line 119

def shoutcase joiner = '_'
  shoutwords.join(joiner)
end

#shoutwordsObject



113
114
115
116
117
# File 'lib/activefacts/support.rb', line 113

def shoutwords
  map do |word|
    word.upcase
  end
end

#snakecase(joiner = '_') ⇒ Object



109
110
111
# File 'lib/activefacts/support.rb', line 109

def snakecase joiner = '_'
  snakewords.join(joiner)
end

#snakewordsObject



103
104
105
106
107
# File 'lib/activefacts/support.rb', line 103

def snakewords
  map do |w|
    w.downcase
  end
end

#titlecaseObject



74
75
76
# File 'lib/activefacts/support.rb', line 74

def titlecase
  titlewords.join('')
end

#titlewordsObject



68
69
70
71
72
# File 'lib/activefacts/support.rb', line 68

def titlewords
  map do |word|
    word[0].upcase+word[1..-1].downcase
  end
end

#to_aObject



123
124
125
# File 'lib/activefacts/support.rb', line 123

def to_a
  self
end

#to_sObject



64
65
66
# File 'lib/activefacts/support.rb', line 64

def to_s
  titlecase
end