class CsvShaper::Shaper
Shaper
Core CsvShaper
class. Delegates header and row generating.
Attributes
Public Class Methods
Source
# File lib/csv_shaper/shaper.rb, line 11 def self.config=(new_config) @config = new_config end
Source
# File lib/csv_shaper/shaper.rb, line 87 def self.configure(&block) @config ||= CsvShaper::Config.new(&block) end
Public: Create an instance of the config and cache it for reference by the Encoder
later
Source
# File lib/csv_shaper/shaper.rb, line 36 def self.encode(options = {}) new(options).tap { |shaper| yield shaper }.to_csv end
Public: creates a new instance of Shaper
taps it with with the given block and encodes it to a String of CSV data Example: “‘ data = CsvShaper::Shaper.encode
do |csv|
csv.rows @users do |csv, user| csv.cells :name, :age, :gender end
end
puts data
> “Name,Age,Gendern‘Joe Bloggs’,25,‘M’n‘John Smith’,34,‘M’”¶ ↑
“‘
Returns a String
Source
# File lib/csv_shaper/shaper.rb, line 15 def initialize(options = {}) @rows = [] local_configuration(options) yield self if block_given? end
Public Instance Methods
Source
Source
Private Instance Methods
Source
# File lib/csv_shaper/shaper.rb, line 93 def local_configuration(options = {}) @local_config = CsvShaper::Config.new do |csv| options.each_pair { |k, v| csv.send("#{k}=", v) } end end