Class: Germinator::SeedFile
- Inherits:
-
Object
- Object
- Germinator::SeedFile
- Defined in:
- lib/germinator/seed_file.rb
Overview
A helper class to parse a seed file name and return the appropriate values
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#basename ⇒ Object
Returns the base file name of the seed file.
-
#class_name ⇒ Object
Returns the name of the class for the seed file.
-
#initialize(path) ⇒ SeedFile
constructor
Inititalize the class instance.
-
#name ⇒ Object
Returns the name portion of the seed file.
-
#seed_name ⇒ Object
Returns the full seed name of the seed file (no path or extension).
-
#to_s ⇒ Object
Override the to_s method to make it more readable.
-
#version ⇒ Object
Returns the version portion of the seed file.
Constructor Details
#initialize(path) ⇒ SeedFile
Inititalize the class instance.
Parameters:
path => The full path of the seed file being parsed.
20 21 22 |
# File 'lib/germinator/seed_file.rb', line 20 def initialize path @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/germinator/seed_file.rb', line 11 def path @path end |
Instance Method Details
#basename ⇒ Object
Returns the base file name of the seed file.
28 29 30 |
# File 'lib/germinator/seed_file.rb', line 28 def basename Pathname.new(@path).basename.to_s end |
#class_name ⇒ Object
Returns the name of the class for the seed file.
63 64 65 |
# File 'lib/germinator/seed_file.rb', line 63 def class_name name.camelize end |
#name ⇒ Object
Returns the name portion of the seed file.
46 47 48 49 50 |
# File 'lib/germinator/seed_file.rb', line 46 def name parts = basename.split('_', 2) return "" if parts.length <= 1 return parts[1].gsub(/\.rb/, "").to_s end |
#seed_name ⇒ Object
Returns the full seed name of the seed file (no path or extension).
55 56 57 |
# File 'lib/germinator/seed_file.rb', line 55 def seed_name "#{version}_#{name}" end |
#to_s ⇒ Object
Override the to_s method to make it more readable.
71 72 73 |
# File 'lib/germinator/seed_file.rb', line 71 def to_s "[#{version}] #{class_name}" end |
#version ⇒ Object
Returns the version portion of the seed file.
36 37 38 39 40 |
# File 'lib/germinator/seed_file.rb', line 36 def version parts = basename.split('_', 2) return "" if parts.length === 0 return parts[0] end |