Class: Grandfather::Md
- Inherits:
-
Object
- Object
- Grandfather::Md
- Defined in:
- lib/grandfather/md.rb
Overview
Class load files and determine if valid
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Md
constructor
A new instance of Md.
- #valid? ⇒ Boolean
- #valid_format?(format) ⇒ Boolean
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/grandfather/md.rb', line 7 def data @data end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/grandfather/md.rb', line 7 def filename @filename end |
#name ⇒ Object (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
16 17 18 |
# File 'lib/grandfather/md.rb', line 16 def valid? valid_format? @extension end |
#valid_format?(format) ⇒ 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 |