Created
November 7, 2013 21:39
-
-
Save lgrains/7362281 to your computer and use it in GitHub Desktop.
Taking a vote. Which looks cleaner and more rubyesque?
This file contains 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 'ostruct' | |
class Instrument < OpenStruct | |
def self.instruments_array | |
InstrumentsCSVReader.get_from_file | |
end | |
def self.all | |
@all ||= instruments_array.map { |n| new(n) } | |
end | |
def self.find(description) | |
all.find { |n| n.name == description } | |
end | |
class InstrumentsCSVReader | |
require 'csv' | |
def self.get_from_file | |
instruments_array=[] | |
CSV.foreach("tmp/instruments.csv", headers: true) do |row| | |
instruments_array << { colleague_code: row["Key"], name: row["Description"] } | |
end | |
instruments_array | |
end | |
end | |
end |
This file contains 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 'ostruct' | |
class Instrument < OpenStruct | |
def self.all | |
@all ||= InstrumentsCSVReader.new.map { |n| new(n) } | |
end | |
def self.find(description) | |
all.find { |n| n.name == description } | |
end | |
class InstrumentsCSVReader < Array | |
require 'csv' | |
def initialize | |
super() | |
get_from_file | |
end | |
def get_from_file | |
CSV.foreach("tmp/instruments.csv", headers: true) do |row| | |
self << { colleague_code: row["Key"], name: row["Description"] } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment