Class: FileNameInfo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ FileNameInfo

Returns a new instance of FileNameInfo.



4
5
6
7
8
9
10
11
# File 'lib/file_name_info.rb', line 4

def initialize(params = {})
  @name = params[:name]
  @year = params[:year]
  @raw_name = params[:raw_name]
  @location = params[:location]
  @series = params[:series]
  @episode = params[:episode]
end

Instance Attribute Details

#episodeObject

Returns the value of attribute episode.



2
3
4
# File 'lib/file_name_info.rb', line 2

def episode
  @episode
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/file_name_info.rb', line 2

def location
  @location
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/file_name_info.rb', line 2

def name
  @name
end

#raw_nameObject

Returns the value of attribute raw_name.



2
3
4
# File 'lib/file_name_info.rb', line 2

def raw_name
  @raw_name
end

#seriesObject

Returns the value of attribute series.



2
3
4
# File 'lib/file_name_info.rb', line 2

def series
  @series
end

#yearObject

Returns the value of attribute year.



2
3
4
# File 'lib/file_name_info.rb', line 2

def year
  @year
end

Instance Method Details

#<=>(other) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/file_name_info.rb', line 27

def <=>(other)
  if series && other.series && series != other.series
    return (series <=> other.series) 
  elsif episode && other.episode && episode != other.episode
    return (episode <=> other.episode)
  elsif name != other.name
    return (name <=> other.name)
  elsif year && other.year
    #Note: with year we want newest first
    return (other.year <=> year)
  else
    return 0
  end
end

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/file_name_info.rb', line 13

def to_s
  s = ''
  if @name
    s += @name
    s += " (#{@year})" if @year
    s += " S: #{@series} E: #{@episode}" if @series || @episode
  elsif @raw_name
    s += @raw_name
  else
    s += @location
  end
  s
end