Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/inat-channel/data_types.rb
Instance Method Summary collapse
Instance Method Details
#limit(len) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/inat-channel/data_types.rb', line 29 def limit len return self if length <= len short = self[0, len] last_space = short.rindex(/\s/) last_sign = short.rindex(/[,.;:!?]/) if last_space if last_sign && last_sign + 1 > last_space return short[0, last_sign + 1] + '...' end return short[0, last_space] + '...' else if last_sign return short[0, last_sign + 1] + '...' end return short + '...' end end |
#to_tag ⇒ Object
26 27 28 |
# File 'lib/inat-channel/data_types.rb', line 26 def to_tag "\##{self.gsub(/\s+/, '_').gsub(/-/, '_').gsub(/[^a-zA-Zа-яА-ЯёЁ_]/, '')}" end |