parseitc 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Changelog +4 -0
  2. data/lib/parseitc.rb +23 -20
  3. metadata +2 -2
data/Changelog CHANGED
@@ -6,3 +6,7 @@ Tue 2010-02-02 - v0.1.1
6
6
  - Typos were fixed
7
7
  - price was renamed to less confusing royalty_price
8
8
  - filenames can be array or string
9
+
10
+ Tue 2010-02-02 - v0.1.2
11
+ - getcaliper.com changes
12
+ - todo: should really use TDD // rspec
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
- # filenames can be either string or array
7
- def initialize(filenames=[])
5
+ Version = '0.1.2'
6
+ # files can be either string or array
7
+ def initialize(files=[])
8
8
  @transactions = []
9
- filenames = [filenames].flatten
10
- filenames.each{|f| add_file f} unless filenames.empty?
9
+ [files].flatten.each do |file|
10
+ add_file file
11
+ end
11
12
  end
12
13
 
13
- def add_file filename
14
- lines = File.readlines(filename)
14
+ def add_file file
15
+ lines = File.readlines(file)
15
16
  lines.shift if lines.first.match(/^Provider/)
16
- lines.each do |t|
17
- add_transaction t
17
+ lines.each do |xion|
18
+ add_transaction xion
18
19
  end
19
20
  end
20
21
 
21
22
  def add_transaction transaction
22
- values = transaction.split(/\t|\n/)
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
- if match = /numbers_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
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 |t|
44
- value = t.send(field.to_sym)
45
- values[value] ||= 0
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.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-09-03 00:00:00 -07:00
12
+ date: 2010-02-02 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15