Class: CsvBlueprints::Blueprint

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

Instance Method Summary collapse

Constructor Details

#initializeBlueprint

Returns a new instance of Blueprint.



45
46
47
# File 'lib/csv_blueprints/blueprint.rb', line 45

def initialize
  @columns = []
end

Instance Method Details

#column(name, value: nil) ⇒ Object



49
50
51
# File 'lib/csv_blueprints/blueprint.rb', line 49

def column(name, value: nil)
  @columns << column_for_value(name, value)
end

#column_namesObject



63
64
65
# File 'lib/csv_blueprints/blueprint.rb', line 63

def column_names
  @columns.map(&:name)
end

#columns(*names, value:) ⇒ Object



53
54
55
56
57
# File 'lib/csv_blueprints/blueprint.rb', line 53

def columns(*names, value:)
  wrapped_value = value.respond_to?(:call) ? RepeatedValue.new(value, names.length) : value

  names.each { |name| column(name, value: wrapped_value) }
end

#default_values(row) ⇒ Object



67
68
69
# File 'lib/csv_blueprints/blueprint.rb', line 67

def default_values(row)
  Hash[@columns.map { |c| [c.name, c.value_for(row)] }]
end

#planObject



59
60
61
# File 'lib/csv_blueprints/blueprint.rb', line 59

def plan
  PlanBuilder.new(self)
end