Class: Ansei::FileInfo
- Inherits:
-
Object
- Object
- Ansei::FileInfo
- Defined in:
- lib/ansei/fileinfo.rb
Overview
File information for Ansei
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#build ⇒ Object
Get the file’s build directory.
-
#destination ⇒ Object
Get the file’s destination filename.
-
#ext ⇒ Object
Get the file’s extension.
-
#exts ⇒ Object
Get the destination file extension, and all other possible extensions for its type.
-
#initialize(type, file) ⇒ FileInfo
constructor
Initialize a new FileInfo object.
-
#name ⇒ Object
Get the ‘basename’ for the file.
-
#source ⇒ Object
Get the file’s source directory.
Constructor Details
#initialize(type, file) ⇒ FileInfo
Initialize a new FileInfo object
type - ‘standardized’ type of file file - filename for file
Returns a new FileInfo object
12 13 14 15 |
# File 'lib/ansei/fileinfo.rb', line 12 def initialize(type, file) @type = type @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/ansei/fileinfo.rb', line 4 def file @file end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/ansei/fileinfo.rb', line 4 def type @type end |
Instance Method Details
#build ⇒ Object
Get the file’s build directory
Returns a string
20 21 22 |
# File 'lib/ansei/fileinfo.rb', line 20 def build Ansei.config[:directories][type].last end |
#destination ⇒ Object
Get the file’s destination filename
Returns a string
27 28 29 30 31 |
# File 'lib/ansei/fileinfo.rb', line 27 def destination dir = Ansei.config[:directories][:build] "#{dir}/#{name}" end |
#ext ⇒ Object
Get the file’s extension
Returns a string
36 37 38 |
# File 'lib/ansei/fileinfo.rb', line 36 def ext Utils.file_ext(file, true) end |
#exts ⇒ Object
Get the destination file extension, and all other possible extensions for its type
Returns an array
44 45 46 |
# File 'lib/ansei/fileinfo.rb', line 44 def exts Ansei.config[:extensions][type] end |
#name ⇒ Object
Get the ‘basename’ for the file
Returns a string
51 52 53 54 55 56 57 58 59 |
# File 'lib/ansei/fileinfo.rb', line 51 def name name = file.sub("#{source}/", '') name = name.sub(Utils.file_ext(file), '') name = Utils.string_urlify(name) if type == :markdown name = "#{build}/#{name}.#{exts.first}" name.sub(/\A\//, '') end |
#source ⇒ Object
Get the file’s source directory
Returns a string
64 65 66 |
# File 'lib/ansei/fileinfo.rb', line 64 def source Ansei.config[:directories][type].first end |