Class: Addic7ed::Filename
- Inherits:
-
Object
- Object
- Addic7ed::Filename
- Defined in:
- lib/addic7ed/filename.rb
Constant Summary collapse
- TVSHOW_REGEX =
/\A(?<showname>.*\w)[\[\. ]+S?(?<season>\d{1,2})[-\. ]?[EX]?(?<episode>\d{2})[\]\. ]+(?<tags>.*)-(?<group>\w*)(\.\w{3})?\z/i
Instance Attribute Summary collapse
-
#episode ⇒ Object
readonly
Returns the value of attribute episode.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#season ⇒ Object
readonly
Returns the value of attribute season.
-
#showname ⇒ Object
readonly
Returns the value of attribute showname.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#basename ⇒ Object
Lazy getters.
- #dirname ⇒ Object
- #encoded_showname ⇒ Object
- #extname ⇒ Object
-
#initialize(filename) ⇒ Filename
constructor
A new instance of Filename.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(filename) ⇒ Filename
Returns a new instance of Filename.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/addic7ed/filename.rb', line 8 def initialize(filename) @filename = filename match = TVSHOW_REGEX.match basename if match @showname = match[:showname].gsub('.', ' ') @season = match[:season].to_i @episode = match[:episode].to_i @tags = match[:tags].upcase.split(/[\. ]/) @group = match[:group].upcase else raise InvalidFilename end end |
Instance Attribute Details
#episode ⇒ Object (readonly)
Returns the value of attribute episode.
6 7 8 |
# File 'lib/addic7ed/filename.rb', line 6 def episode @episode end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/addic7ed/filename.rb', line 6 def filename @filename end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
6 7 8 |
# File 'lib/addic7ed/filename.rb', line 6 def group @group end |
#season ⇒ Object (readonly)
Returns the value of attribute season.
6 7 8 |
# File 'lib/addic7ed/filename.rb', line 6 def season @season end |
#showname ⇒ Object (readonly)
Returns the value of attribute showname.
6 7 8 |
# File 'lib/addic7ed/filename.rb', line 6 def showname @showname end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
6 7 8 |
# File 'lib/addic7ed/filename.rb', line 6 def @tags end |
Instance Method Details
#basename ⇒ Object
Lazy getters
35 36 37 |
# File 'lib/addic7ed/filename.rb', line 35 def basename @basename ||= File.basename(@filename) end |
#dirname ⇒ Object
39 40 41 |
# File 'lib/addic7ed/filename.rb', line 39 def dirname @dirname ||= File.dirname(@filename) end |
#encoded_showname ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/addic7ed/filename.rb', line 22 def encoded_showname @showname. gsub(/ /, '_'). gsub(/_US$/, '_(US)'). gsub(/_US_/, '_(US)_'). gsub(/_UK$/, ''). gsub(/_UK_/, '_'). gsub(/_\d{4}$/, ''). gsub(/_\d{4}_/, '_') end |
#extname ⇒ Object
43 44 45 |
# File 'lib/addic7ed/filename.rb', line 43 def extname @extname ||= File.extname(@filename) end |
#inspect ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/addic7ed/filename.rb', line 51 def inspect "Guesses for #{@filename}: show: #{@showname} season: #{@season} episode: #{@episode} tags: #{@tags} group: #{@group}" end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/addic7ed/filename.rb', line 47 def to_s @filename end |