Last active
August 29, 2015 14:21
-
-
Save olistik/0e5719d2477669466f36 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
module Timesheets | |
class << self | |
def text_to_fragment_list(text:) | |
text.split(',') | |
end | |
def normalize_fragment_list(fragment_list:) | |
fragment_list.map(&:strip) | |
end | |
def fragment_list_to_line(fragment_list:) | |
{ | |
first_name: fragment_list[0], | |
employee_id: fragment_list[1], | |
office: fragment_list[2] | |
} | |
end | |
def line_to_string(line:) | |
[ | |
"Office: #{line[:office]}", | |
"Employee ID: #{line[:employee_id]}", | |
"First name: #{line[:first_name]}" | |
].join(', ') | |
end | |
end | |
end | |
File.open('timesheets.txt', 'r') do |file| | |
file. | |
each_line. | |
lazy. | |
map {|text| Timesheets::text_to_fragment_list(text: text)}. | |
map {|fragment_list| Timesheets::normalize_fragment_list(fragment_list: fragment_list)}. | |
map {|fragment_list| Timesheets::fragment_list_to_line(fragment_list: fragment_list)}. | |
map {|line| Timesheets::line_to_string(line: line)}. | |
each {|string| puts string} | |
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