Im using the following code:
class Target <
Struct.new(:question)
#Struct.new(:action, :blank, :cost, :status, :due_date,
:responsibility)
def print_csv_record
# use the ternary operator to use one output format or the other
question.length==0 ? printf(",") : printf("\"%s\",", question)
printf("\n")
end
end
CSV.open('ActionPlan.csv','rb').each do |row|
t = Target.new
t.question = row[1] if row[0].to_s.match(/1.[a-z]/)#maybe can use
each.line
pp t.question #<---to test outputs
end
The outputs are as followed:
nil
nil
nil
"Maximise use of natural lighting"
"Turn-off unnecessary lights/equipment"
"Install energy efficient lighting"
"Turn-off unnecessary air conditioning"
"Repair or replace damaged oven/refrigerator seals"
"Install draught proofing"
"Consider energy efficiency labels when buying electrical items"
"Insulate hot water pipes"
......
......
For some reason, ruby returns the entire line of row[1]. If i only
require one result at a time (i.e only "Turn-off unnecessary
lights/equipment") and do not want ruby to return any 'nil' output, how
can i tell ruby to do so?
Attached is the .csv file use. Thanks for any help
Nizam
Attachments:
http://www.ruby-forum.com/attachment/5806/ActionPlan.csv
···
--
Posted via http://www.ruby-forum.com/.