Class: FileStruct

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

Direct Known Subclasses

XMLFileStruct, YAMLFileStruct

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ FileStruct

Returns a new instance of FileStruct.



5
6
7
8
9
10
11
# File 'lib/file_struct.rb', line 5

def initialize(path, options = {})
  @path = path
  @basename = File.basename(path)
  @ext = File.extname(path)
  @content = options[:content] || File.read(@path)
  @version = options[:version]
end

Instance Attribute Details

#basenameObject

Returns the value of attribute basename.



2
3
4
# File 'lib/file_struct.rb', line 2

def basename
  @basename
end

#contentObject

Returns the value of attribute content.



2
3
4
# File 'lib/file_struct.rb', line 2

def content
  @content
end

#extObject (readonly)

Returns the value of attribute ext.



3
4
5
# File 'lib/file_struct.rb', line 3

def ext
  @ext
end

#pathObject

Returns the value of attribute path.



2
3
4
# File 'lib/file_struct.rb', line 2

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/file_struct.rb', line 3

def version
  @version
end

Instance Method Details

#basic_nameObject



13
14
15
# File 'lib/file_struct.rb', line 13

def basic_name
  File.basename(@path, @ext)
end

#reload!Object



21
22
23
# File 'lib/file_struct.rb', line 21

def reload!
  @content = File.read(@path)
end

#save!Object



25
26
# File 'lib/file_struct.rb', line 25

def save!
end