Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/heartwood/support/string.rb
Instance Method Summary collapse
Instance Method Details
#paragraphs ⇒ Object
12 13 14 15 |
# File 'lib/heartwood/support/string.rb', line 12 def paragraphs pattern = /\n/ split(pattern).map(&:strip).reject(&:blank?) end |
#possessive ⇒ Object
8 9 10 |
# File 'lib/heartwood/support/string.rb', line 8 def possessive self + ('s' == self[-1, 1] ? "'" : "'s") end |
#sentences ⇒ Object
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_bool ⇒ Object
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 |