Method: Onoma::Nomenclature#to_csv
- Defined in:
- lib/onoma/nomenclature.rb
#to_csv(file, _options = {}) ⇒ Object
Write CSV file with all items an there properties
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/onoma/nomenclature.rb', line 69 def to_csv(file, = {}) properties = @properties.values CSV.open(file, 'wb') do |csv| csv << [:name] + properties.map do |p| suffix = if p.decimal? ' D' elsif p.integer? ' I' elsif p.boolean? ' B' elsif p.item? " R(#{p.choices_nomenclature})" else '' end "#{p.name}#{suffix}" end @items.values.each do |i| csv << [i.name] + properties.map { |p| i.attributes[p.name] } end end end |