Created
July 24, 2018 09:07
-
-
Save quanon/43f3f9191c8048f3e7bb568f2d497201 to your computer and use it in GitHub Desktop.
CSV から値を取得するのに便利なクラス
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
require 'forwardable' | |
class CSVRows | |
extend Forwardable | |
attr_reader :csv_path | |
def_delegators :each, *Enumerable.instance_methods(false) | |
def initialize(csv_path) | |
@csv_path = csv_path | |
end | |
def each | |
return enum_for(:each) unless block_given? | |
File.open(csv_path, 'rb:Shift_JIS:UTF-8', undef: :replace) do |f| | |
CSV.new(f).each do |row| | |
yield(row) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment