Class: WebCrawler::View::Csv
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #format(item) ⇒ Object
-
#initialize(input, options = { }) ⇒ Csv
constructor
A new instance of Csv.
Methods inherited from Base
Constructor Details
#initialize(input, options = { }) ⇒ Csv
Returns a new instance of Csv.
5 6 7 8 9 10 11 12 13 |
# File 'lib/web_crawler/view/csv.rb', line 5 def initialize(input, = { }) in_group_of_num = .delete(:in_group_of) input = input.first.in_groups_of(in_group_of_num) if in_group_of_num && input.size == 1 headers = .delete(:headers) || input.select { |i| i.is_a? Hash }.max_by(&:size).keys rescue NoMethodError ensure input = input.dup.unshift(headers) unless headers.nil? super(input, ) end |
Instance Method Details
#format(item) ⇒ Object
15 16 17 18 |
# File 'lib/web_crawler/view/csv.rb', line 15 def format(item) values = item.respond_to?(:values) ? item.values : item.to_a values.to_csv(@options[:csv] || {}) end |