Class: Audio

Inherits:
Zarchitect show all
Defined in:
lib/zarchitect/audio.rb

Constant Summary

Constants inherited from Zarchitect

Zarchitect::ASSETDIR, Zarchitect::ASSETSDIR, Zarchitect::BUILDIR, Zarchitect::CONFIGDIR, Zarchitect::DEBUGSDIR, Zarchitect::DRAFTDIR, Zarchitect::FILEDIR, Zarchitect::FILESDIR, Zarchitect::HTMLDIR, Zarchitect::LAYOUTDIR, Zarchitect::NODEDIR, Zarchitect::SHARESDIR, Zarchitect::VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Zarchitect

#main, #rss

Constructor Details

#initialize(path) ⇒ Audio

Returns a new instance of Audio.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/zarchitect/audio.rb', line 4

def initialize(path)
  @path = path
  @url = path.clone
  @url[0] = "/"
  @size = File.size(path)
  @type = "audio/" << File.extname(path)[1..-1]

  if @size > Zarchitect.conf.audio_limit.to_f.mib_to_bytes
    GPI.print "Error: File #{path} too large "\
      "(#{@size.bytes_to_mib.to_f.round(2)}MiB)."\
      " Allowed size: #{Zarchitect.conf.audio_limit.to_f.mb_to_mib.round(2)}"
    GPI.quit
  end
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



2
3
4
# File 'lib/zarchitect/audio.rb', line 2

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/zarchitect/audio.rb', line 2

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



2
3
4
# File 'lib/zarchitect/audio.rb', line 2

def url
  @url
end

Class Method Details

.find(k, v) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/zarchitect/audio.rb', line 23

def self.find(k, v)
  ObjectSpace.each_object(Audio) do |a|
    str = a.send(k)
    return a if str == v
  end
  nil
end

.is_valid?(filename) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/zarchitect/audio.rb', line 19

def self.is_valid?(filename)
  [".mp3",".ogg"].include?(File.extname(filename))
end