Class: DSNode::Resource
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DSNode::Resource
show all
- Defined in:
- app/models/ds_node/resource.rb
Defined Under Namespace
Classes: UnrecognizedFileType
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#extension ⇒ Object
Returns the value of attribute extension.
11
12
13
|
# File 'app/models/ds_node/resource.rb', line 11
def extension
@extension
end
|
#mime_type ⇒ Object
Returns the value of attribute mime_type.
11
12
13
|
# File 'app/models/ds_node/resource.rb', line 11
def mime_type
@mime_type
end
|
#new_file ⇒ Object
Returns the value of attribute new_file.
11
12
13
|
# File 'app/models/ds_node/resource.rb', line 11
def new_file
@new_file
end
|
Instance Method Details
#audio? ⇒ Boolean
53
54
55
|
# File 'app/models/ds_node/resource.rb', line 53
def audio?
media_type == "a"
end
|
#file=(file) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/models/ds_node/resource.rb', line 16
def file= file
self.original_file_name ||= actual_file_name(file)
file = actual_file(file)
self.new_file = file
set_mime_type
set_type
set_extension
set_dimensions_and_duration
self.file = to_thumbnail_file if needs_processing? end
|
#file_path ⇒ Object
33
34
35
|
# File 'app/models/ds_node/resource.rb', line 33
def file_path
File.join "/assets", path, file_name
end
|
#full_path ⇒ Object
37
38
39
|
# File 'app/models/ds_node/resource.rb', line 37
def full_path
File.join "public", file_path
end
|
#image? ⇒ Boolean
45
46
47
|
# File 'app/models/ds_node/resource.rb', line 45
def image?
media_type == "i"
end
|
#needs_processing? ⇒ Boolean
61
62
63
|
# File 'app/models/ds_node/resource.rb', line 61
def needs_processing?
false
end
|
#pdf? ⇒ Boolean
57
58
59
|
# File 'app/models/ds_node/resource.rb', line 57
def pdf?
media_type == "p"
end
|
65
66
67
|
# File 'app/models/ds_node/resource.rb', line 65
def preferred_format
"jpg"
end
|
#to_thumbnail_file ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'app/models/ds_node/resource.rb', line 69
def to_thumbnail_file
result = Tempfile.new(["result", ".#{preferred_format}"])
if video?
Dir.mktmpdir do |dir|
Dir.chdir dir do
`mplayer -nosound -ss 1 -vf screenshot -frames 1 -vo png:z=9 #{new_file.path} 2>&1`
`convert 00000001.png -resize #{resize_geometry} 00000001.jpg 2>&1`
`mv 00000001.jpg #{result.path} 2>&1`
end
end
else
`convert #{new_file.path}[0] -resize #{resize_geometry} #{result.path} 2>&1`
end
result
end
|
#url ⇒ Object
41
42
43
|
# File 'app/models/ds_node/resource.rb', line 41
def url
file_path
end
|
#video? ⇒ Boolean
49
50
51
|
# File 'app/models/ds_node/resource.rb', line 49
def video?
media_type == "v"
end
|