Class: Skyline::MediaNode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Skyline::MediaNode
- Defined in:
- app/models/skyline/media_node.rb
Class Method Summary collapse
-
.sanitize_filename(filename) ⇒ Object
- sanitize nodename ==== Parameters filename<String>
-
nodename that has to be sanitized.
Instance Method Summary collapse
-
#file_path ⇒ Object
- returns the path of the media node ==== Retruns <String>
-
path.
-
#full_path ⇒ Object
- returns the full path of the media node ==== Retruns <String>
-
Full path including parent and filename.
-
#name=(name) ⇒ Object
return the sanitized nodename as name.
-
#path=(name) ⇒ Object
write the path of the node.
-
#renamed? ⇒ Boolean
- check if node has been renamed after sanitizing the name ==== Returns <Boolean>
-
true if renamed sets @renamed if file was sanitized.
-
#sanitized? ⇒ Boolean
- check if filename has been sanitized ==== Returns <Boolean>
-
true if sanitized.
- #title ⇒ Object
Class Method Details
.sanitize_filename(filename) ⇒ Object
sanitize nodename
Parameters
- filename<String>
-
nodename that has to be sanitized
Returns
- <String>
-
sanitized nodename
18 19 20 21 22 23 |
# File 'app/models/skyline/media_node.rb', line 18 def sanitize_filename(filename) filename = filename.gsub("\\","/") filename = filename.downcase.gsub(/[^a-z0-9\.\-\+_]/,"_").squeeze("_") filename = "_#{filename}" if filename =~ /^\.+$/ filename end |
Instance Method Details
#file_path ⇒ Object
returns the path of the media node
Retruns
- <String>
-
path
76 77 78 |
# File 'app/models/skyline/media_node.rb', line 76 def file_path File.join(self.class.assets_path,self.id.to_s) end |
#full_path ⇒ Object
returns the full path of the media node
Retruns
- <String>
-
Full path including parent and filename
67 68 69 70 71 |
# File 'app/models/skyline/media_node.rb', line 67 def full_path p = File.join(self.path.to_s,self.name) p = p[1,p.size] if p[0,1] == "/" p end |
#name=(name) ⇒ Object
return the sanitized nodename as name
Parameters
- name<String>
-
original nodename
Returns
- <String>
-
satized name
41 42 43 44 45 |
# File 'app/models/skyline/media_node.rb', line 41 def name=(name) name = sanitize_filename(name) @renamed = true if name != self.name self.write_attribute(:name,name) end |
#path=(name) ⇒ Object
write the path of the node
Parameters
- name<String>
-
original nodename
51 52 53 54 |
# File 'app/models/skyline/media_node.rb', line 51 def path=(name) @renamed = true if name != self.name self.write_attribute(:path,name) end |
#renamed? ⇒ Boolean
check if node has been renamed after sanitizing the name
Returns
- <Boolean>
-
true if renamed
sets @renamed if file was sanitized
60 61 62 |
# File 'app/models/skyline/media_node.rb', line 60 def renamed? @renamed end |
#sanitized? ⇒ Boolean
check if filename has been sanitized
Returns
- <Boolean>
-
true if sanitized
30 31 32 |
# File 'app/models/skyline/media_node.rb', line 30 def sanitized? @sanitized end |
#title ⇒ Object
80 81 82 |
# File 'app/models/skyline/media_node.rb', line 80 def title self[:title].present? ? self[:title] : self.name end |