quandl_operation 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7881122ddea828dd458817aa7de4facbb24dd7ba
4
- data.tar.gz: 1604dc65536cce9cf67a8e89a79a872f4ffffa0a
3
+ metadata.gz: b7d2fcd944ad2dc1d1b251472b4fd21246f3d689
4
+ data.tar.gz: e0bc3a24a4069a5ec6b7ba42f2a6e9788f3d99cb
5
5
  SHA512:
6
- metadata.gz: 7c1425f09dcea673d51d707886594de40f1930f0f61e2b176b43047c92dff746e717b3ca44fbf469f2f611dee8ce9157ed36053022068f7775770176875e550c
7
- data.tar.gz: 276cc0608fd53738e2f0874e6edcefe9b882865493f2753f61402ee3c3d10a2eee7c57c1bd238924c75ff45b0056aad9aa6770c2e9c922af673b55489f4477d0
6
+ metadata.gz: f9a93903052832e5567b45a42467e6a0d89d9b7a76800a65d972cfa6cf88a3e973aff49d6bbb7b2eaef50a554312be1349c4e12e30a99c9177cd707c53472f68
7
+ data.tar.gz: 8a4c52d84b8a2bd1701f0436312d4fc87a57c65e7a4bdcdc73acbe5979c3c16d0cc1d0e3738a1ceb6389026c477aac2e94fb8eb6d6adc3c2c75df7b9763743f2
data/UPGRADE.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.21
2
+
3
+ * QDFormat should handle new lines in attributes
4
+
5
+
1
6
  ## 0.1.20
2
7
 
3
8
  * qdformat#to_qdf
@@ -27,9 +27,17 @@ class Dump
27
27
  end
28
28
 
29
29
  def attributes
30
- [:source_code, :code, :name, :description].
31
- inject({}){|m,k| m[k.to_s] = node.send(k) unless node.send(k).blank?; m }.
32
- to_yaml[4..-1]
30
+ attrs = [:source_code, :code, :name, :description].inject({}) do |memo, name|
31
+ name = name.to_s
32
+ memo[name] = node.send(name) if node.respond_to?(name) && node.send(name).present?
33
+ memo[name] = memo[name].gsub("\n", '\n') if memo[name].present?
34
+ memo
35
+ end
36
+ attrs.to_yaml[4..-1]
37
+ end
38
+
39
+ def description
40
+ record.description
33
41
  end
34
42
 
35
43
  def data
@@ -7,14 +7,14 @@ class Quandl::Operation::QDFormat::Load
7
7
  end
8
8
 
9
9
  def from_string(input)
10
- nodes = []
10
+ nodes = [{ attributes: '', data: '' }]
11
11
  input.each_line do |line|
12
12
  # strip whitespace
13
13
  line = line.strip.rstrip
14
14
  # ignore comments and blank lines
15
15
  next if line[0] == '#' || line.blank?
16
16
  # code_format denotes the start of a new node
17
- nodes << { attributes: '', data: '' } if line =~ code_format
17
+ nodes << { attributes: '', data: '' } if line[0..2] == node_delimiter
18
18
  # attribute_format denotes an attribute
19
19
  if line =~ attribute_format
20
20
  # add the attribute to attributes
@@ -26,6 +26,7 @@ class Quandl::Operation::QDFormat::Load
26
26
  end
27
27
  # append the current node
28
28
  nodes = parse_nodes(nodes)
29
+ nodes = initialize_nodes(nodes)
29
30
  nodes
30
31
  end
31
32
 
@@ -34,14 +35,26 @@ class Quandl::Operation::QDFormat::Load
34
35
 
35
36
  def parse_nodes(nodes)
36
37
  nodes.collect do |node|
38
+ # parse attrs as yaml
37
39
  node[:attributes] = YAML.load( node[:attributes] )
40
+ # replace new line characters
41
+ node[:attributes].each do |key, value|
42
+ node[:attributes][key].gsub!('\n', "\n") if node[:attributes][key].respond_to?(:gsub!)
43
+ end
44
+ # parse data as csv
38
45
  node[:attributes][:data] = CSV.parse(node[:data])
46
+ node
47
+ end
48
+ end
49
+
50
+ def initialize_nodes(nodes)
51
+ nodes.collect do |node|
39
52
  Quandl::Operation::QDFormat::Node.new(node[:attributes])
40
53
  end
41
54
  end
42
-
43
- def code_format
44
- /^code: (.+)/
55
+
56
+ def node_delimiter
57
+ '---'
45
58
  end
46
59
 
47
60
  def attribute_format
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Operation
3
- VERSION = "0.1.20"
3
+ VERSION = "0.1.21"
4
4
  end
5
5
  end
@@ -2,26 +2,26 @@
2
2
  require 'quandl/operation/qdformat'
3
3
  require 'spec_helper'
4
4
 
5
- describe Quandl::Operation::QDFormat do
5
+ describe Quandl::Operation::QDFormat::Load do
6
6
 
7
7
  let(:qdf_dataset){
8
8
  %Q{
9
9
  # YAML metadata
10
- code: DATASET_CODE
11
- source_code: SOURCE_CODE
12
- name: Test Dataset Name 1
13
- description: Here is a description with multiple lines.\\n This is the second line.
10
+ source_code: NSE
11
+ code: OIL
12
+ name: Oil India Limited
13
+ description: 'Historical prices for Oil India Limited (OIL), (ISIN: INE274J01014), National \\nStock Exchange of India.'
14
14
  # CSV data
15
15
  Date, Value, High, Low
16
16
  2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353
17
17
  2013-11-19,10.039388096885814,,14.09718770934256
18
+ ---
18
19
 
19
- # Second dataset
20
20
  code: DATASET_CODE_2
21
21
  source_code: SOURCE_CODE_2
22
22
  name: Test Dataset Name 2
23
23
  description: Here is a description with multiple lines.
24
- # CSV data
24
+
25
25
  Date, Value, High, Low
26
26
  2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353
27
27
  2013-11-19,10.039388096885814,,14.09718770934256
@@ -29,10 +29,9 @@ describe Quandl::Operation::QDFormat do
29
29
  }
30
30
  }
31
31
 
32
- let(:collection){ Quandl::Operation::QDFormat.load(qdf_dataset) }
33
-
34
- describe ".load" do
32
+ describe ".from_string" do
35
33
 
34
+ let(:collection){ Quandl::Operation::QDFormat::Load.from_string(qdf_dataset) }
36
35
  subject{ collection }
37
36
 
38
37
  its(:count){ should eq 2 }
@@ -41,13 +40,12 @@ describe Quandl::Operation::QDFormat do
41
40
  subject{ collection.first }
42
41
 
43
42
  it{ should be_a Quandl::Operation::QDFormat::Node }
44
- its(:source_code){ should eq 'SOURCE_CODE' }
45
- its(:code){ should eq 'DATASET_CODE' }
46
- its(:name){ should eq 'Test Dataset Name 1' }
47
- its(:description){ should eq 'Here is a description with multiple lines.\n This is the second line.' }
43
+ its(:source_code){ should eq 'NSE' }
44
+ its(:code){ should eq 'OIL' }
45
+ its(:name){ should eq 'Oil India Limited' }
46
+ its(:description){ should eq "Historical prices for Oil India Limited (OIL), (ISIN: INE274J01014), National \nStock Exchange of India." }
48
47
  its(:column_names){ should eq ['Date', 'Value', 'High', 'Low'] }
49
- its(:data){ should eq [
50
- ["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
48
+ its(:data){ should eq [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
51
49
  ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]] }
52
50
  end
53
51
  end
@@ -8,7 +8,7 @@ describe Quandl::Operation::QDFormat::Node do
8
8
  code: 'DATASET_CODE',
9
9
  source_code: 'SOURCE_CODE',
10
10
  name: 'Test Dataset Name 1',
11
- description: "Here is a description with multiple lines.\\n This is the second line.",
11
+ description: "Here is a description with multiple lines.\n This is the second line.",
12
12
  column_names: ['Date', 'Value', 'High', 'Low'],
13
13
  data: [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
14
14
  ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]],
@@ -19,7 +19,7 @@ describe Quandl::Operation::QDFormat::Node do
19
19
  its(:code){ should eq 'DATASET_CODE' }
20
20
  its(:source_code){ should eq 'SOURCE_CODE' }
21
21
  its(:name){ should eq 'Test Dataset Name 1' }
22
- its(:description){ should eq "Here is a description with multiple lines.\\n This is the second line." }
22
+ its(:description){ should eq "Here is a description with multiple lines.\n This is the second line." }
23
23
  its(:column_names){ should eq ['Date', 'Value', 'High', 'Low'] }
24
24
  its(:data){ should eq [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
25
25
  ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
@@ -158,8 +158,8 @@ files:
158
158
  - spec/lib/quandl/operation/collapse_spec.rb
159
159
  - spec/lib/quandl/operation/date_spec.rb
160
160
  - spec/lib/quandl/operation/parse_spec.rb
161
+ - spec/lib/quandl/operation/qdformat/load_spec.rb
161
162
  - spec/lib/quandl/operation/qdformat/node_spec.rb
162
- - spec/lib/quandl/operation/qdformat_spec.rb
163
163
  - spec/lib/quandl/operation/transform_spec.rb
164
164
  - spec/spec_helper.rb
165
165
  homepage: http://blake.hilscher.ca/
@@ -190,7 +190,7 @@ test_files:
190
190
  - spec/lib/quandl/operation/collapse_spec.rb
191
191
  - spec/lib/quandl/operation/date_spec.rb
192
192
  - spec/lib/quandl/operation/parse_spec.rb
193
+ - spec/lib/quandl/operation/qdformat/load_spec.rb
193
194
  - spec/lib/quandl/operation/qdformat/node_spec.rb
194
- - spec/lib/quandl/operation/qdformat_spec.rb
195
195
  - spec/lib/quandl/operation/transform_spec.rb
196
196
  - spec/spec_helper.rb