Class: Bloggit::Media

Inherits:
Object
  • Object
show all
Defined in:
lib/bloggit/media.rb

Overview

Media

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, site) ⇒ Media

Returns a new instance of Media.



9
10
11
12
13
14
15
16
17
# File 'lib/bloggit/media.rb', line 9

def initialize(path, site)
  @site = site
  @full_path = path
  @relative_path = path.gsub(File.join(site.base_path, 'media', ''), '')
  # Read file info and set Media properties...
  @filename = File.basename(path)
  @ext = File.extname(path)
  # TODO: name, size, dimensions
end

Instance Attribute Details

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def dimensions
  @dimensions
end

#extObject (readonly)

Returns the value of attribute ext.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def ext
  @ext
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def filename
  @filename
end

#full_pathObject (readonly)

Returns the value of attribute full_path.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def full_path
  @full_path
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def name
  @name
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def relative_path
  @relative_path
end

#siteObject (readonly)

Returns the value of attribute site.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def site
  @site
end

#sizeObject (readonly)

Returns the value of attribute size.



7
8
9
# File 'lib/bloggit/media.rb', line 7

def size
  @size
end

Class Method Details

.from_file(path, site) ⇒ Object

Creates a Media object from an image on the filesystem



33
34
35
36
37
# File 'lib/bloggit/media.rb', line 33

def from_file(path, site) 
  path = File.expand_path(path)
  raise "File must exist" unless File.exists?( path )
  new( path, site )
end

Instance Method Details

#create_thumbnail(size = nil) ⇒ Object



22
23
# File 'lib/bloggit/media.rb', line 22

def create_thumbnail(size=nil)
end


25
26
27
# File 'lib/bloggit/media.rb', line 25

def permalink
  "media/#{@relative_path}"
end

#thumbnail_path(size = nil) ⇒ Object



19
20
# File 'lib/bloggit/media.rb', line 19

def thumbnail_path(size=nil)
end