Skip to content

Instantly share code, notes, and snippets.

@olistik
Last active August 29, 2015 14:21
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/0e5719d2477669466f36 to your computer and use it in GitHub Desktop.
Save olistik/0e5719d2477669466f36 to your computer and use it in GitHub Desktop.
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
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