Class: Morion::File

Inherits:
Object
  • Object
show all
Defined in:
lib/morion/file.rb

Constant Summary collapse

FILENAME_REGEX =
/(?:.+\/)([^#?]+)/
EXTENSION_REGEX =
/\.[^.]*$/

Instance Method Summary collapse

Constructor Details

#initialize(path, assets_paths, rails_root) ⇒ File

Returns a new instance of File.



6
7
8
9
10
# File 'lib/morion/file.rb', line 6

def initialize(path, assets_paths, rails_root)
  @path = path
  @assets_paths = assets_paths
  @rails_root = rails_root
end

Instance Method Details

#asset_pathObject



20
21
22
23
24
25
26
27
28
# File 'lib/morion/file.rb', line 20

def asset_path
  file_path = @path

  @assets_paths.each do |rails_path|
    file_path = file_path.gsub("#{rails_path}/", "")
  end

  file_path
end

#extensionObject



16
17
18
# File 'lib/morion/file.rb', line 16

def extension
  filename.match(EXTENSION_REGEX)[1]
end

#filenameObject



12
13
14
# File 'lib/morion/file.rb', line 12

def filename
  @path.match(FILENAME_REGEX)[1]
end

#folder_pathObject



30
31
32
# File 'lib/morion/file.rb', line 30

def folder_path
  @path.gsub(@rails_root, "").match(/(.*)\/.*/)[1]
end