Created
May 19, 2015 10:04
-
-
Save olistik/ad33366e7d0da5c1f257 to your computer and use it in GitHub Desktop.
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
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 |
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
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