Class: SimpleCataloger::Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SimpleCataloger::Tag
- Defined in:
- lib/dircat/cat_on_sqlite/model/tag.rb
Constant Summary collapse
- RE_TAG =
/\[([^\]]+)\]/
- RE_RATING =
/^\d$/
- RE_YEAR =
/^\d\d\d\d$/
- MATCHES =
[ [RE_RATING, "rating", proc { |tag_name| tag_name.to_i }], [RE_YEAR, "year", proc { |tag_name| tag_name.to_i }] ]
Class Method Summary collapse
- .extract_name(dir_or_file_name) ⇒ Object
-
.extract_tags(dir_or_file_name) ⇒ Object
extracts tags from directory or file name.
-
.match_category(tag_name) ⇒ Object
decode standard tags.
Class Method Details
.extract_name(dir_or_file_name) ⇒ Object
27 28 29 |
# File 'lib/dircat/cat_on_sqlite/model/tag.rb', line 27 def self.extract_name(dir_or_file_name) dir_or_file_name.gsub(Tag::RE_TAG, '').strip end |
.extract_tags(dir_or_file_name) ⇒ Object
extracts tags from directory or file name
17 18 19 20 21 22 23 24 25 |
# File 'lib/dircat/cat_on_sqlite/model/tag.rb', line 17 def self.(dir_or_file_name) = [] match_data = dir_or_file_name.match(RE_TAG) while match_data << match_data[1] match_data = dir_or_file_name.match(RE_TAG, match_data.end(0)) end end |
.match_category(tag_name) ⇒ Object
decode standard tags
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dircat/cat_on_sqlite/model/tag.rb', line 42 def self.match_category(tag_name) MATCHES.each do |re, category_name, convert| if re.match tag_name category = Category.find_or_create_by_name(category_name) tag = Tag.find_or_create_by_name_and_category_id( convert.call(tag_name), category.id ) return category end end nil end |