Module: TF2R::TextHelpers
Overview
This module provides common methods for manipulating text throughout this gem. Common operations include messing with Steam ID 64s, hex color codes, and link to resources on TF2R.
Instance Method Summary collapse
-
#extract_color(str) ⇒ String
Extracts a hex color code.
-
#extract_link_snippet(text) ⇒ String
Extract the link_snippet from a path or link.
-
#extract_steam_id(href) ⇒ Fixnum
Extracts a SteamID64 from a TF2R user link.
-
#raffle_link(link_snippet) ⇒ String
Generates the TF2R link for a raffle given a link snippet.
-
#raffle_link_full(link_snippet) ⇒ String
Generates the full TF2R link for a raffle given a link snippet.
-
#user_link(steam_id) ⇒ String
Generates the TF2R link for a user given a Steam ID.
Instance Method Details
#extract_color(str) ⇒ String
Extracts a hex color code.
13 14 15 |
# File 'lib/tf2r/text_helpers.rb', line 13 def extract_color(str) /#(\w+)\s*;/.match(str)[1].downcase end |
#extract_link_snippet(text) ⇒ String
Extract the link_snippet from a path or link.
21 22 23 |
# File 'lib/tf2r/text_helpers.rb', line 21 def extract_link_snippet(text) /\/(k.+)\.html/.match(text)[1] end |
#extract_steam_id(href) ⇒ Fixnum
Extracts a SteamID64 from a TF2R user link.
33 34 35 |
# File 'lib/tf2r/text_helpers.rb', line 33 def extract_steam_id(href) /http:\/\/tf2r.com\/user\/(\d+)\.html/.match(href)[1].to_i end |
#raffle_link(link_snippet) ⇒ String
Generates the TF2R link for a raffle given a link snippet.
44 45 46 |
# File 'lib/tf2r/text_helpers.rb', line 44 def raffle_link(link_snippet) "http://tf2r.com/#{link_snippet}.html" end |
#raffle_link_full(link_snippet) ⇒ String
Generates the full TF2R link for a raffle given a link snippet.
57 58 59 |
# File 'lib/tf2r/text_helpers.rb', line 57 def raffle_link_full(link_snippet) "#{raffle_link(link_snippet)}?full" end |
#user_link(steam_id) ⇒ String
Generates the TF2R link for a user given a Steam ID.
69 70 71 |
# File 'lib/tf2r/text_helpers.rb', line 69 def user_link(steam_id) "http://tf2r.com/user/#{steam_id}.html" end |