Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/heartwood/support/string.rb

Instance Method Summary collapse

Instance Method Details

#paragraphsObject



12
13
14
15
# File 'lib/heartwood/support/string.rb', line 12

def paragraphs
  pattern = /\n/
  split(pattern).map(&:strip).reject(&:blank?)
end

#possessiveObject



8
9
10
# File 'lib/heartwood/support/string.rb', line 8

def possessive
  self + ('s' == self[-1, 1] ? "'" : "'s")
end

#sentencesObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/heartwood/support/string.rb', line 17

def sentences
  pattern = /[\.\?\!]/
  punctuation = scan(pattern)
  sentences = split(pattern).map(&:strip).reject(&:blank?)
  return sentences if punctuation.blank?
  sentences.each_with_index do |txt, idx|
    next if punctuation[idx].blank?
    sentences[idx] += punctuation[idx]
  end
  sentences
end

#to_boolObject

Raises:

  • (ArgumentError)


2
3
4
5
6
# File 'lib/heartwood/support/string.rb', line 2

def to_bool
  return true if self == true || self =~ (/^(true|t|yes|y|1)$/i)
  return false if self == false || self.blank? || self =~ (/^(false|f|no|n|0)$/i)
  raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end