Class: Ansei::FileInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ansei/fileinfo.rb

Overview

File information for Ansei

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/ansei/fileinfo.rb', line 4

def file
  @file
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/ansei/fileinfo.rb', line 4

def type
  @type
end

Instance Method Details

#buildObject

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

#destinationObject

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

#extObject

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

#extsObject

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

#nameObject

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

#sourceObject

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