parseitc 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +4 -0
- data/lib/parseitc.rb +23 -20
- metadata +2 -2
data/Changelog
CHANGED
data/lib/parseitc.rb
CHANGED
@@ -2,48 +2,50 @@
|
|
2
2
|
module ParseITC
|
3
3
|
class TransactionParser
|
4
4
|
attr_accessor :transactions
|
5
|
-
Version = '0.1'
|
6
|
-
#
|
7
|
-
def initialize(
|
5
|
+
Version = '0.1.2'
|
6
|
+
# files can be either string or array
|
7
|
+
def initialize(files=[])
|
8
8
|
@transactions = []
|
9
|
-
|
10
|
-
|
9
|
+
[files].flatten.each do |file|
|
10
|
+
add_file file
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
|
-
def add_file
|
14
|
-
lines = File.readlines(
|
14
|
+
def add_file file
|
15
|
+
lines = File.readlines(file)
|
15
16
|
lines.shift if lines.first.match(/^Provider/)
|
16
|
-
lines.each do |
|
17
|
-
add_transaction
|
17
|
+
lines.each do |xion|
|
18
|
+
add_transaction xion
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def add_transaction transaction
|
22
|
-
|
23
|
-
raise WrongNumberOfElementsException.new(27, values.length) unless values.length == 27
|
24
|
-
@transactions << Transaction.new(values)
|
23
|
+
@transactions << Transaction.new(transaction.split(/\t|\n/))
|
25
24
|
end
|
26
25
|
|
27
26
|
private
|
28
27
|
def method_missing(method_id, *arguments)
|
29
|
-
|
28
|
+
match = /numbers_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
|
29
|
+
if match
|
30
30
|
numbers_by(match)
|
31
31
|
else
|
32
32
|
super
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def allowed_fields
|
37
|
+
first_xion = @transactions.first
|
38
|
+
first_xion.instance_variables.map{|field| field[1..-1]} +
|
39
|
+
first_xion.public_methods
|
40
|
+
end
|
41
|
+
|
36
42
|
def numbers_by(match)
|
37
|
-
# puts match.captures.first == "country"
|
38
43
|
field = match.captures.first
|
39
|
-
allowed_fields = @transactions.first.instance_variables.map{|f| f[1..-1]} +
|
40
|
-
@transactions.first.public_methods
|
41
44
|
raise NoMethodError.new("#{match}") unless allowed_fields.include? field
|
42
45
|
values = {}
|
43
|
-
@transactions.map do |
|
44
|
-
value =
|
45
|
-
values[value]
|
46
|
-
values[value] += t.units.to_i
|
46
|
+
@transactions.map do |xion|
|
47
|
+
value = xion.send(field.to_sym)
|
48
|
+
values[value] = (values[value] || 0) + xion.units.to_i
|
47
49
|
end
|
48
50
|
values
|
49
51
|
end
|
@@ -74,6 +76,7 @@ module ParseITC
|
|
74
76
|
alias :price :royalty_price
|
75
77
|
|
76
78
|
def initialize array
|
79
|
+
raise WrongNumberOfElementsException.new(27, array.length) unless array.length == 27
|
77
80
|
@provider = array[0]
|
78
81
|
@provider_country = array[1]
|
79
82
|
@company = array[5]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parseitc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HJ Choi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-02 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|