Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/tit.rb
Constant Summary collapse
- URI_REGEX =
%r"((?:(?:[^ :/?#]+):)(?://(?:[^ /?#]*))(?:[^ ?#]*)(?:\?(?:[^ #]*))?(?:#(?:[^ ]*))?)"
Instance Method Summary collapse
- #replace_uris(old, newt) ⇒ Object
- #replace_with_expanded_url(expanded) ⇒ Object
- #replace_with_expanded_url!(expanded) ⇒ Object
- #wrapped(cols) ⇒ Object
Instance Method Details
#replace_uris(old, newt) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/tit.rb', line 31 def replace_uris(old, newt) split(URI_REGEX).collect do |s| if s =~ URI_REGEX s.gsub(old, newt.join) else s end end.join end |
#replace_with_expanded_url(expanded) ⇒ Object
28 29 30 |
# File 'lib/tit.rb', line 28 def () replace_uris(/http:\/\/t.co\/[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY0123456789]/, ) end |
#replace_with_expanded_url!(expanded) ⇒ Object
25 26 27 |
# File 'lib/tit.rb', line 25 def () replace(()) end |
#wrapped(cols) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tit.rb', line 13 def wrapped(cols) curlen = 0 split.inject([[]]) do |rows, word| if curlen + word.length > cols curlen = word.length + 1 rows << [word] else curlen += word.length + 1 rows << (rows.pop << word) end end.map { |row| row.join(' ') } end |