Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/spotlite/string_extensions.rb

Instance Method Summary collapse

Instance Method Details

#clean_credits_textObject



55
56
57
# File 'lib/spotlite/string_extensions.rb', line 55

def clean_credits_text
  gsub(' and', '').gsub(' &', '').gsub(') (', ', ').gsub('(', '').gsub(')', '')
end

#clean_descriptionObject

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_hrefObject

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_nameObject

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_commentObject

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_taglineObject

Removes tagline comment in braces



46
47
48
# File 'lib/spotlite/string_extensions.rb', line 46

def clean_tagline
  gsub(/\[(.*?)\]:?|\((.*?)\):?/, '').strip
end

#parse_dateObject

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_idObject

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_yearObject

: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_whitespaceObject

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_yearObject

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