efo_nelfo 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 894a44091085c1483965076057f66f3d3a8ed7fe
4
- data.tar.gz: 1d26149077017f057cb31df8c8029c7ee226cd26
3
+ metadata.gz: 78ab950b02b7049200da1e0e5de3b2e652dafd54
4
+ data.tar.gz: 179c82aa18e4812ac7850cdcf368bad9dfa66b43
5
5
  SHA512:
6
- metadata.gz: dacd19af0a3f6ef369a723820d03c7787ff2989f946e89e3ece4900c97818fd8fa0c485c94b476e92ab3757ebf8d594d2b7c1590de4e4a84249cbb0344129848
7
- data.tar.gz: 70e158b44c968e0f2056adfbccf27b1e8e8d6338dc6d1f99e9b9e462a55469ad634a23407896f4f674768e0d65ad9a9f87e72df2d748654f5b8ef16db183566a
6
+ metadata.gz: a0d8371775eed749b0f1ee7351f4cdb03fffa79d4d9bc806394e034e9f7b623d980aa535b37c55aa21472743915b73e34b65c14023d94f3518de6d0699b40f31
7
+ data.tar.gz: d18f93c56c3b188942a84ee39a6b5b7269f38fe732c53f799f0c00c2fe6463d8bc828e646afa30fe4a5241bf05c6b42a2f3dab6d5b1d4d2b8a96b520025d8487
@@ -35,10 +35,18 @@ module EfoNelfo
35
35
  self.for(hash[:post_type], hash[:version]).new(hash)
36
36
  end
37
37
 
38
+ def parse(csv)
39
+ new EfoNelfo::Reader::CSV.new(data: csv).first
40
+ end
41
+
38
42
  end
39
43
 
40
44
  def initialize(*args)
41
- initialize_attributes(*args)
45
+ if args && args.first.is_a?(Array)
46
+ initialize_attributes Hash[properties.keys.zip(args.first)]
47
+ else
48
+ initialize_attributes(*args)
49
+ end
42
50
  end
43
51
 
44
52
  def post_type
@@ -29,7 +29,7 @@ module EfoNelfo
29
29
 
30
30
  def parse
31
31
  # Create the head object based on the first row
32
- head = parse_head csv.first
32
+ head = parse_head first
33
33
  head.source = @data
34
34
 
35
35
  # Read rest of the file and add them to the head
@@ -38,28 +38,23 @@ module EfoNelfo
38
38
  klass = EfoNelfo::PostType.for row[0], head.version
39
39
  next if klass.nil?
40
40
 
41
- line = initialize_object_with_properties klass, row
42
- head.add line
41
+ head.add klass.new(row)
43
42
  end
44
43
 
45
44
  head
46
45
  end
47
46
 
47
+ # Returns the first row of the csv file
48
+ def first
49
+ csv.first
50
+ end
51
+
48
52
  private
49
53
 
50
54
  def parse_head(row)
51
55
  klass = EfoNelfo::PostType.for row[0], row[2]
52
56
  raise EfoNelfo::UnsupportedPostType.new("Don't know how to handle v#{row[2]} of #{row[0]}") if klass.nil?
53
-
54
- initialize_object_with_properties klass, row
55
- end
56
-
57
- def initialize_object_with_properties(klass, columns)
58
- object = klass.new
59
- object.class.properties.each_with_index do |property, i|
60
- object.send "#{property.first}=", columns[i]
61
- end
62
- object
57
+ klass.new row
63
58
  end
64
59
 
65
60
  end
@@ -1,3 +1,3 @@
1
1
  module EfoNelfo
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -15,3 +15,16 @@ end
15
15
  def csv(filename)
16
16
  File.expand_path("../samples/#{filename}", __FILE__)
17
17
  end
18
+
19
+ # Add 'its' to minitest - copied from https://github.com/agileanimal/its-minitest (gem doesn't work)
20
+ class MiniTest::Spec
21
+ def self.its attribute, &block
22
+ describe "verify subject.#{attribute} for" do
23
+ let(:inner_subject) { subject.send(attribute) }
24
+
25
+ it "verify subject.#{attribute} for" do
26
+ inner_subject.instance_eval &block
27
+ end
28
+ end
29
+ end
30
+ end
data/spec/vl_spec.rb CHANGED
@@ -4,6 +4,31 @@ describe EfoNelfo::V40::VL do
4
4
 
5
5
  let(:vl) { EfoNelfo::V40::VL.new }
6
6
 
7
+ describe '.parse' do
8
+ let(:csv) { "VL;4;9455483;10-13 AF-2 Armaflex rull/krt.;35 mtr/krt. Cellegummi;2;MTR;METER;3500;10000;20130401;2;;P94551;ARMACELL G;;J;;;B" }
9
+ subject { EfoNelfo::V40::VL.parse csv }
10
+
11
+ it { subject.must_be_instance_of EfoNelfo::V40::VL }
12
+
13
+ its(:product_type) { must_equal 4 }
14
+ its(:post_type) { must_equal "VL" }
15
+ its(:product_type) { must_equal 4 }
16
+ its(:product_number) { must_equal "9455483" }
17
+ its(:name) { must_equal "10-13 AF-2 Armaflex rull/krt." }
18
+ its(:description) { must_equal "35 mtr/krt. Cellegummi" }
19
+ its(:unit) { must_equal 2 }
20
+ its(:price_unit) { must_equal "MTR" }
21
+ its(:price_unit_desc) { must_equal "METER" }
22
+ its(:price) { must_equal 3500 }
23
+ its(:amount) { must_equal 10000 }
24
+ its(:price_date) { must_equal Date.new(2013,4,1) }
25
+ its(:status) { must_equal 2 }
26
+ its(:block_number) { must_be_nil }
27
+ its(:discount_group) { must_equal "P94551" }
28
+ its(:fabrication) { must_equal "ARMACELL G" }
29
+ its(:type) { must_be_nil }
30
+ end
31
+
7
32
  it "#weight returns the weight in gram" do
8
33
  vl.info << { field: 'VEKT', value: 250 }
9
34
  vl.weight.must_equal 250
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: efo_nelfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gudleik Rasch