Class: UnitF::Tag::AutoTags
- Inherits:
-
Hash
- Object
- Hash
- UnitF::Tag::AutoTags
- Defined in:
- lib/unitf/tag/auto_tags.rb
Instance Method Summary collapse
- #auto_tag_path ⇒ Object
- #from_file ⇒ Object
- #from_path ⇒ Object
-
#initialize(file_path) ⇒ AutoTags
constructor
A new instance of AutoTags.
Constructor Details
#initialize(file_path) ⇒ AutoTags
4 5 6 7 8 9 10 11 12 |
# File 'lib/unitf/tag/auto_tags.rb', line 4 def initialize(file_path) super @file_path = ::File.realpath(file_path.to_s) @dirname = ::File.dirname(@file_path) merge!(from_path) merge!(from_file) end |
Instance Method Details
#auto_tag_path ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/unitf/tag/auto_tags.rb', line 14 def auto_tag_path return @auto_tag_path unless @auto_tag_path.nil? ["#{@dirname}/.autotag", "#{@dirname}/../.autotag"].each do |path| return @auto_tag_path = path if ::File.exist?(path) end nil end |
#from_file ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/unitf/tag/auto_tags.rb', line 46 def from_file = {} return unless ::File.exist?(auto_tag_path) ::File.read(auto_tag_path).each_line do |line| line.chomp! tag, value = line.split(/\s*=\s*/) [tag.strip.to_sym] = value.strip end rescue StandardError {} end |
#from_path ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/unitf/tag/auto_tags.rb', line 24 def from_path = {} [:title] = ::File.basename(@file_path) [:track] = [:title].match(/^\s*\d+/).to_s.to_i # Specific formatting for dated radio if [:title].scan(/(\.|_|-)((\d\d\d\d)(\.|-)\d\d(\.|-)\d\d(\w*))\./).any? [:title] = ::Regexp.last_match[2] [:year] = ::Regexp.last_match[3].to_i else [:title].gsub!(/\.\w+$/, '') [:title].gsub!(/^\d*\s*(-|\.)*\s*/, '') end path_parts = @dirname.to_s.split('/') [:artist] = path_parts[-2] [:album] = path_parts[-1] end |