Skip to content

Instantly share code, notes, and snippets.

@olistik
Created May 19, 2015 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olistik/ad33366e7d0da5c1f257 to your computer and use it in GitHub Desktop.
Save olistik/ad33366e7d0da5c1f257 to your computer and use it in GitHub Desktop.
class LinePresenter
def initialize(object)
@object = object
end
def to_s
"Office: #{@object.office}, Employee ID: #{@object.employee_id}, First name: #{@object.first_name}"
end
end
class Line
attr_reader :line
def initialize(text:)
@line = text
end
def office
values[2].strip
end
def employee_id
values[1].strip
end
def first_name
name = values[0]
name.split[0]
end
private
def values
@values ||= line.split(',')
end
end
File.open('timesheets.txt', 'r') do |file|
file.
each_line.
lazy.
map {|text| Line.new(text: text)}.
map {|line| LinePresenter.new(line)}.
each {|line| puts line}
end
Tony Stark, 1111, Desio, x1
Barry Allen, 2222, Desio, x2
Bruce Wayne, 3333, Desio, x3
Kal El, 4444, Desio, x4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment