Class: Grandfather::Md

Inherits:
Object
  • Object
show all
Defined in:
lib/grandfather/md.rb

Overview

Class load files and determine if valid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Md

Returns a new instance of Md.



9
10
11
12
13
14
# File 'lib/grandfather/md.rb', line 9

def initialize(filename)
  @filename = filename
  @extension = ::File.extname(@filename)
  @name = ::File.basename(@filename, @extension)
  @data = ::File.open(@filename, 'rb' ) { |f| f.read } if ::File.exists?(@filename)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/grandfather/md.rb', line 7

def data
  @data
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/grandfather/md.rb', line 7

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/grandfather/md.rb', line 7

def name
  @name
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/grandfather/md.rb', line 16

def valid?
  valid_format? @extension
end

#valid_format?(format) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/grandfather/md.rb', line 20

def valid_format?(format)
  # All the files are missing extensions, if it has an extension it is wrong
    # kinda hacky not happy with it
  format.empty?
  #return false if format.nil?

  #format.to_sym == :md
end