Class: MovableErb
- Inherits:
-
Object
- Object
- MovableErb
- Defined in:
- lib/movable_erb.rb
Overview
Defined Under Namespace
Constant Summary collapse
- VERSION =
File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).chomp
- DEFAULT_TEMPLATE =
File.(File.dirname(__FILE__) + '/templates/mtimport.erb')
Instance Attribute Summary collapse
-
#csv ⇒ Object
Returns the value of attribute csv.
-
#erb ⇒ Object
Returns the value of attribute erb.
-
#separator ⇒ Object
Returns the value of attribute separator.
Instance Method Summary collapse
-
#convert ⇒ String
Converts each row of the CSV file and collects it into @results.
-
#initialize(options = {}) ⇒ MovableErb
constructor
A new instance of MovableErb.
Constructor Details
#initialize(options = {}) ⇒ MovableErb
Returns a new instance of MovableErb.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/movable_erb.rb', line 13 def initialize( = {}) @erb = MovableErb::Erb.setup do |erb| erb.template = [:template] || DEFAULT_TEMPLATE end if [:csv] @csv = MovableErb::CSV.setup do |csv| csv.filename = [:csv] end end @separator = [:separator] || "" end |
Instance Attribute Details
#csv ⇒ Object
Returns the value of attribute csv.
4 5 6 |
# File 'lib/movable_erb.rb', line 4 def csv @csv end |
#erb ⇒ Object
Returns the value of attribute erb.
4 5 6 |
# File 'lib/movable_erb.rb', line 4 def erb @erb end |
#separator ⇒ Object
Returns the value of attribute separator.
4 5 6 |
# File 'lib/movable_erb.rb', line 4 def separator @separator end |
Instance Method Details
#convert ⇒ String
Converts each row of the CSV file and collects it into @results
28 29 30 31 32 33 34 35 36 |
# File 'lib/movable_erb.rb', line 28 def convert @results = [] csv.parse! csv.hashes.each do |hash_data| erb.data = hash_data @results << erb.build! end @results.join(separator) end |