Skip to content

Commit

Permalink
Merge 2dbb397 into bd1d7a2
Browse files Browse the repository at this point in the history
  • Loading branch information
falti committed Jan 5, 2015
2 parents bd1d7a2 + 2dbb397 commit a2a62ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
20 changes: 10 additions & 10 deletions lib/haecksler/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,9 @@ def parse(string_value)
when :float
Float(string_value)
when :date
if date_format.nil?
Date.parse(string_value)
else
Date.strptime(string_value, date_format)
end
parse_date(Date, string_value)
when :datetime
if date_format.nil?
DateTime.parse(string_value)
else
DateTime.strptime(string_value, date_format)
end
parse_date(DateTime, string_value)
else
nil
end
Expand All @@ -72,5 +64,13 @@ def parse(string_value)

parsed
end

def parse_date(clazz, string_value)
if date_format.nil?
clazz.parse(string_value)
else
clazz.strptime(string_value, date_format)
end
end
end
end
28 changes: 17 additions & 11 deletions lib/haecksler/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,30 @@ def [](key)
end

def parse(input)

total_number_of_characters = columns.map(&:size).reduce(&:+)
input = input.slice(0, total_number_of_characters)
@columns = parsed_columns(slices(input))
self
end

indizes = columns.map(&:size).reduce([0]) do |memo,item|
memo << (memo.last.to_i + item)
memo
end

slices = input.split(//).each_with_index.slice_before { | element | indizes.include? element[1] }
def total_number_of_characters
columns.map(&:size).reduce(&:+)
end

parsed_columns = slices.map {|slice| slice.map{|i| i[0]}.join("")}.zip(columns).map do |text, column|
def parsed_columns(slices)
slices.map {|slice| slice.map{|i| i[0]}.join("")}.zip(columns).map do |text, column|
column.parse(text)
end
end

@columns = parsed_columns
def indizes
columns.map(&:size).reduce([0]) do |memo,item|
memo << (memo.last.to_i + item)
memo
end
end

self
def slices(input)
input.split(//).each_with_index.slice_before { | element | indizes.include? element[1] }
end

def header?
Expand Down

0 comments on commit a2a62ae

Please sign in to comment.