class String

Public Instance Methods

clean_credits_text() click to toggle source
# File lib/spotlite/string_extensions.rb, line 55
def clean_credits_text
  gsub(' and', '').gsub(' &', '').gsub(') (', ', ').gsub('(', '').gsub(')', '')
end
clean_description() click to toggle source

Strips “See full summary”, “Written by”, and “Add a plot” in movie description and storyline

# 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() click to toggle source

Cleans 'href' param of an <a> tag

# File lib/spotlite/string_extensions.rb, line 26
def clean_href
  gsub(/(\?|&)ref.+/, '').gsub('/country/', '').gsub('/language/', '')
end
clean_name() click to toggle source

Strip all extra text from person's name node

# File lib/spotlite/string_extensions.rb, line 36
def clean_name
  gsub(/\n.+$/, '')
end
clean_release_comment() click to toggle source

Strips parantheses from release date's comment

# File lib/spotlite/string_extensions.rb, line 51
def clean_release_comment
  gsub("\n", '').gsub(') (', ', ').gsub('(', '').gsub(')', '')
end
clean_tagline() click to toggle source

Removes tagline comment in braces

# File lib/spotlite/string_extensions.rb, line 46
def clean_tagline
  gsub(/\[(.*?)\]:?|\((.*?)\):?/, '').strip
end
parse_date() click to toggle source

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'

# 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() click to toggle source

Parses 7-digit IMDb ID, usually from a URL

# File lib/spotlite/string_extensions.rb, line 31
def parse_imdb_id
  self[/\d{7}/] unless self.nil?
end
strip_whitespace() click to toggle source

Strip a string from all extra white space

# File lib/spotlite/string_extensions.rb, line 41
def strip_whitespace
  gsub(/\u00A0/, '').gsub(/\s+/, ' ').strip
end
strip_year() click to toggle source

Strips 4 digits in braces and a single space before from a string like 'Movie Title (2013)'

# File lib/spotlite/string_extensions.rb, line 21
def strip_year
  gsub(/\s\(\d{4}\)/, '')
end