Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/spotlite/string_extensions.rb
Instance Method Summary collapse
- #clean_credits_text ⇒ Object
-
#clean_description ⇒ Object
Strips “See full summary”, “Written by”, and “Add a plot” in movie description and storyline.
-
#clean_href ⇒ Object
Cleans ‘href’ param of an <a> tag.
-
#clean_name ⇒ Object
Strip all extra text from person’s name node.
-
#clean_release_comment ⇒ Object
Strips parantheses from release date’s comment.
-
#clean_tagline ⇒ Object
Removes tagline comment in braces.
-
#parse_date ⇒ Object
Parses date from a string like ‘20 Jan 2013’, ‘Mar 2013’, or ‘2013’.
-
#parse_imdb_id ⇒ Object
Parses 7-digit IMDb ID, usually from a URL.
-
#parse_year ⇒ Object
:nodoc:.
-
#strip_whitespace ⇒ Object
Strip a string from all extra white space.
-
#strip_year ⇒ Object
Strips 4 digits in braces and a single space before from a string like ‘Movie Title (2013)’.
Instance Method Details
#clean_credits_text ⇒ Object
55 56 57 |
# File 'lib/spotlite/string_extensions.rb', line 55 def clean_credits_text gsub(' and', '').gsub(' &', '').gsub(') (', ', ').gsub('(', '').gsub(')', '') end |
#clean_description ⇒ Object
Strips “See full summary”, “Written by”, and “Add a plot” in movie description and storyline
60 61 62 |
# File 'lib/spotlite/string_extensions.rb', line 60 def clean_description gsub(/((?:\sWritten by)(?!.*(?:\sWritten by)).*)/m, '').gsub(/((?:\sSee full summary)(?!.*(?:\sSee full summary)).*)/m, '').gsub('Add a Plot', '').strip end |
#clean_href ⇒ Object
Cleans ‘href’ param of an <a> tag
26 27 28 |
# File 'lib/spotlite/string_extensions.rb', line 26 def clean_href gsub(/(\?|&)ref.+/, '').gsub('/country/', '').gsub('/language/', '') end |
#clean_name ⇒ Object
Strip all extra text from person’s name node
36 37 38 |
# File 'lib/spotlite/string_extensions.rb', line 36 def clean_name gsub(/\n.+$/, '') end |
#clean_release_comment ⇒ Object
Strips parantheses from release date’s comment
51 52 53 |
# File 'lib/spotlite/string_extensions.rb', line 51 def clean_release_comment gsub("\n", '').gsub(') (', ', ').gsub('(', '').gsub(')', '') end |
#clean_tagline ⇒ Object
Removes tagline comment in braces
46 47 48 |
# File 'lib/spotlite/string_extensions.rb', line 46 def clean_tagline gsub(/\[(.*?)\]:?|\((.*?)\):?/, '').strip end |
#parse_date ⇒ Object
Parses date from a string like ‘20 Jan 2013’, ‘Mar 2013’, or ‘2013’. Will return 01-Mar-2013 in case of ‘Mar 2013’. Will return 01-Jan-2013 in case of ‘2013’
7 8 9 10 11 12 13 |
# File 'lib/spotlite/string_extensions.rb', line 7 def parse_date begin length > 4 ? Date.parse(self) : Date.new(self.to_i) rescue ArgumentError nil end end |
#parse_imdb_id ⇒ Object
Parses 7-digit IMDb ID, usually from a URL
31 32 33 |
# File 'lib/spotlite/string_extensions.rb', line 31 def parse_imdb_id self[/\d{7}/] unless self.nil? end |
#parse_year ⇒ Object
:nodoc:
15 16 17 18 |
# File 'lib/spotlite/string_extensions.rb', line 15 def parse_year # :nodoc: year = self[/\d{4}/].to_i year > 0 ? year : nil end |
#strip_whitespace ⇒ Object
Strip a string from all extra white space
41 42 43 |
# File 'lib/spotlite/string_extensions.rb', line 41 def strip_whitespace gsub(/\u00A0/, '').gsub(/\s+/, ' ').strip end |
#strip_year ⇒ Object
Strips 4 digits in braces and a single space before from a string like ‘Movie Title (2013)’
21 22 23 |
# File 'lib/spotlite/string_extensions.rb', line 21 def strip_year gsub(/\s\(\d{4}\)/, '') end |