-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
131 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- encoding : utf-8 -*- | ||
|
||
class FileReader | ||
|
||
attr_accessor :filename | ||
attr_accessor :participants | ||
attr_accessor :nb_tableaux_parse | ||
attr_accessor :depenses | ||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Participants: Penny, Sheldon, Leonard, Rajesh | ||
|
||
## Day 1 | ||
- Sheldon 132 2 packbags [Leonard, Penny] | ||
- Leonard 32 bad restaurant | ||
- Penny 23 watter bottle airport [Sheldon] | ||
- Leonard 50 good restaurant | ||
## Day 2 | ||
- Penny 33 tour effeil Visit [Leonard, Rajesh, Penny] | ||
- Rajesh 3 toilets for Sheldon [Sheldon] | ||
- Rajesh 6,5 bus tickets | ||
- Leonard 43 restaurant |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- encoding : utf-8 -*- | ||
require 'rubygems' | ||
# require 'matrix' | ||
|
||
require_relative 'depenses' | ||
require_relative 'file_reader' | ||
|
||
class TxtReader < FileReader | ||
|
||
def initialize(filename, config) | ||
@filename = filename | ||
parse | ||
end | ||
|
||
protected | ||
|
||
def parse | ||
@participants = nil | ||
f = File.open(filename, "r") | ||
|
||
# Scan for participants | ||
while true | ||
line = f.gets | ||
if line.nil? | ||
# end of reached without finding participants ? | ||
raise 'participants list not found in file' | ||
break | ||
end | ||
if line.match(/^Participants:\s*([\w-]+(\s*,\s*[\w-]+)*)/) | ||
@participants = $1.scan(/[\w-]+/) | ||
break | ||
end | ||
end | ||
|
||
# Scan for expenses | ||
@depenses = Depenses.new(@participants) | ||
while line = f.gets | ||
next if line[0] == '#' or line.strip.empty? # Ignore commented lines | ||
if line.match(/^\s*[-*]\s*([\w-]+)\s+(\d+([\.,]\d+)?)\s+([^\[\]]+)\s+(\[([\w-]+)(\s*,\s*[\w-]+)*\])?/) | ||
# Match something like "- Chris 4.5 tickets for boat [Bruno, Chris]" | ||
payer = $1 | ||
amount = to_f($2) | ||
why = $4 | ||
concerned_persons = $5 ? $5.scan(/[\w-]+/) : :tous | ||
@depenses.ajouter_depense(payer, amount, concerned_persons, why) | ||
else | ||
raise "Unparsed line: #{line}" | ||
end | ||
end | ||
end | ||
|
||
def to_f(str) | ||
return str.tr(',','.').to_f | ||
end | ||
|
||
end |