quandl_operation 0.1.22 → 0.1.23

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: 0ae58461349d4ba8c510ee5a0361b2502fb38867
4
- data.tar.gz: a683b6d46cfa49cfb783fc8de468f22612f9e3e8
3
+ metadata.gz: 24dc5a778c39638babaa1bb5640e042a26ffba1c
4
+ data.tar.gz: c4f5211b7f4425f872939e7bb08c12a955af4691
5
5
  SHA512:
6
- metadata.gz: e83c29041365745773cffadbe0f913bcbbe828ed26bba60a71cd9b6a04dbdae620d4029e055ed74557e3bcbfcb37a150963d885cdd4cc97ba0fb338d6228d4c8
7
- data.tar.gz: 61b2c18bdbcfd7efd021ae4e98029a2f890055f9794c3903cfaf425072622231131e0b88113723552f7e4f14af5986abe0f1267f9fe468efcd84078c12a8a91c
6
+ metadata.gz: d12d77624a61d51560f2d214189b826174a8bc291460a2651d8075fe398418925fc4e6fb1bda4155d7f566ce70932edc8858330c477f4c2d8191f420f70e5f85
7
+ data.tar.gz: 60f8fdb3179b09437abe62f09dd720d43167ce3bab8ca5ad567c56450aba674c870738f9410f926d63be54bd559e0e042465720b719a080d8cb8bcc3ae1d501e
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Operation
3
- VERSION = "0.1.22"
3
+ VERSION = "0.1.23"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-25 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -148,18 +148,12 @@ files:
148
148
  - lib/quandl/operation/core_ext/string.rb
149
149
  - lib/quandl/operation/core_ext/time.rb
150
150
  - lib/quandl/operation/parse.rb
151
- - lib/quandl/operation/qdformat.rb
152
- - lib/quandl/operation/qdformat/dump.rb
153
- - lib/quandl/operation/qdformat/load.rb
154
- - lib/quandl/operation/qdformat/node.rb
155
151
  - lib/quandl/operation/transform.rb
156
152
  - lib/quandl/operation/version.rb
157
153
  - quandl_operation.gemspec
158
154
  - spec/lib/quandl/operation/collapse_spec.rb
159
155
  - spec/lib/quandl/operation/date_spec.rb
160
156
  - spec/lib/quandl/operation/parse_spec.rb
161
- - spec/lib/quandl/operation/qdformat/load_spec.rb
162
- - spec/lib/quandl/operation/qdformat/node_spec.rb
163
157
  - spec/lib/quandl/operation/transform_spec.rb
164
158
  - spec/spec_helper.rb
165
159
  homepage: http://blake.hilscher.ca/
@@ -190,7 +184,5 @@ test_files:
190
184
  - spec/lib/quandl/operation/collapse_spec.rb
191
185
  - spec/lib/quandl/operation/date_spec.rb
192
186
  - spec/lib/quandl/operation/parse_spec.rb
193
- - spec/lib/quandl/operation/qdformat/load_spec.rb
194
- - spec/lib/quandl/operation/qdformat/node_spec.rb
195
187
  - spec/lib/quandl/operation/transform_spec.rb
196
188
  - spec/spec_helper.rb
@@ -1,58 +0,0 @@
1
- module Quandl
2
- module Operation
3
- class QDFormat
4
-
5
- class Dump
6
-
7
- ATTRIBUTES = [:source_code, :code, :name, :description]
8
-
9
- class << self
10
-
11
- def nodes(*args)
12
- Array(args).flatten.collect{|r| node(r) }.join("\n")
13
- end
14
-
15
- def node(node)
16
- self.new(node).to_qdf
17
- end
18
-
19
- end
20
-
21
- attr_accessor :node
22
-
23
- def initialize(r)
24
- self.node = r
25
- end
26
-
27
- def to_qdf
28
- [ attributes,
29
- "-\n",
30
- column_names,
31
- data
32
- ].compact.join
33
- end
34
-
35
- def attributes
36
- attrs = ATTRIBUTES.inject({}) do |memo, name|
37
- name = name.to_s
38
- memo[name] = node.send(name) if node.respond_to?(name) && node.send(name).present?
39
- memo
40
- end
41
- attrs.to_yaml[4..-1]
42
- end
43
-
44
- def data
45
- data = node.data.is_a?(Array) ? node.data.collect(&:to_csv).join : node.data
46
- data = data.to_csv if data.respond_to?(:to_csv)
47
- data
48
- end
49
-
50
- def column_names
51
- node.column_names.to_csv if node.column_names.present?
52
- end
53
-
54
- end
55
-
56
- end
57
- end
58
- end
@@ -1,70 +0,0 @@
1
- class Quandl::Operation::QDFormat::Load
2
-
3
- SECTION_DELIMITER = '-'
4
-
5
- class << self
6
-
7
- def from_file(path)
8
- from_string(File.read(path).strip)
9
- end
10
-
11
- def from_string(input)
12
- nodes = []
13
- section_type = :data
14
- input.each_line do |rline|
15
- # strip whitespace
16
- line = rline.strip.rstrip
17
- # ignore comments and blank lines
18
- next if line[0] == '#' || line.blank?
19
-
20
- # are we looking at an attribute?
21
- if line =~ attribute_format
22
- # if we are leaving the data section
23
- # then this is the start of a new node
24
- nodes << { attributes: '', data: '' } if section_type == :data
25
- # update the section to attributes
26
- section_type = :attributes
27
-
28
- # have we reached the end of the attributes?
29
- elsif line[0] == '-'
30
- # update the section to data
31
- section_type = :data
32
- # skip to the next line
33
- next
34
- end
35
- # add the line to it's section in the current node.
36
- # YAML must include whitespace
37
- nodes[-1][section_type] += (section_type == :data) ? "#{line}\n" : rline
38
- end
39
- # append the current node
40
- nodes = parse_nodes(nodes)
41
- nodes = initialize_nodes(nodes)
42
- nodes
43
- end
44
-
45
-
46
- protected
47
-
48
- def parse_nodes(nodes)
49
- nodes.collect do |node|
50
- # parse attrs as yaml
51
- node[:attributes] = YAML.load( node[:attributes] )
52
- # parse data as csv
53
- node[:attributes][:data] = CSV.parse(node[:data])
54
- node
55
- end
56
- end
57
-
58
- def initialize_nodes(nodes)
59
- nodes.collect do |node|
60
- Quandl::Operation::QDFormat::Node.new(node[:attributes])
61
- end
62
- end
63
-
64
- def attribute_format
65
- /^([a-z0-9_]+): (.+)/
66
- end
67
-
68
- end
69
-
70
- end
@@ -1,51 +0,0 @@
1
- class Quandl::Operation::QDFormat::Node
2
-
3
- ATTRIBUTES = :source_code, :code, :name, :description, :column_names, :data
4
- attr_accessor *ATTRIBUTES
5
-
6
- def initialize(attrs)
7
- assign_attributes(attrs)
8
- end
9
-
10
- def assign_attributes(attrs)
11
- attrs.each do |key, value|
12
- self.send("#{key}=", value) if self.respond_to?(key)
13
- end
14
- end
15
-
16
- def attributes
17
- ATTRIBUTES.inject({}){|m,k| m[k] = self.send(k); m }
18
- end
19
-
20
- def inspect
21
- "<##{self.class.name} #{attributes.to_s} >"
22
- end
23
-
24
- def full_code=(value)
25
- value = value.split('/')
26
- self.source_code = value[0]
27
- self.code = value[1]
28
- end
29
-
30
- def full_code
31
- [source_code, code].join('/')
32
- end
33
-
34
- def description=(value)
35
- @description = value.to_s.gsub('\n', "\n")
36
- end
37
-
38
- def data=(rows)
39
- self.column_names = rows.shift unless rows.first.collect{|r| r.to_s.numeric? }.include?(true)
40
- @data = rows
41
- end
42
-
43
- def column_names=(names)
44
- @column_names = Array(names).flatten.collect{|n| n.strip.rstrip }
45
- end
46
-
47
- def to_qdf
48
- Quandl::Operation::QDFormat::Dump.node(self)
49
- end
50
-
51
- end
@@ -1,24 +0,0 @@
1
- require 'csv'
2
- require 'yaml'
3
-
4
- require 'quandl/operation/qdformat/dump'
5
- require 'quandl/operation/qdformat/load'
6
- require 'quandl/operation/qdformat/node'
7
-
8
- class Quandl::Operation::QDFormat
9
- class << self
10
-
11
- def load(input)
12
- Quandl::Operation::QDFormat::Load.from_string(input)
13
- end
14
-
15
- def load_file(file_path)
16
- Quandl::Operation::QDFormat::Load.from_file(file_path)
17
- end
18
-
19
- def dump(nodes)
20
- Quandl::Operation::QDFormat::Dump.nodes(nodes)
21
- end
22
-
23
- end
24
- end
@@ -1,55 +0,0 @@
1
- # encoding: utf-8
2
- require 'quandl/operation/qdformat'
3
- require 'spec_helper'
4
-
5
- describe Quandl::Operation::QDFormat::Load do
6
-
7
- let(:qdf_dataset){
8
- %Q{
9
- # first dataset
10
- source_code: NSE
11
- code: OIL
12
- name: Oil India Limited
13
- description: |-
14
- Here is a description with multiple lines.
15
- This is the second line.
16
- -
17
- Date, Value, High, Low
18
- 2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353
19
- 2013-11-19,10.039388096885814,,14.09718770934256
20
-
21
- # Second dataset
22
- code: DATASET_CODE_2
23
- source_code: SOURCE_CODE_2
24
- name: Test Dataset Name 2
25
- description: Here is a description with multiple lines.
26
- -
27
- Date, Value, High, Low
28
- 2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353
29
- 2013-11-19,10.039388096885814,,14.09718770934256
30
- 2013-11-18,11.039388096885814,,15.09718770934256
31
- }
32
- }
33
-
34
- describe ".from_string" do
35
-
36
- let(:collection){ Quandl::Operation::QDFormat::Load.from_string(qdf_dataset) }
37
- subject{ collection }
38
-
39
- its(:count){ should eq 2 }
40
-
41
- describe "#first" do
42
- subject{ collection.first }
43
-
44
- it{ should be_a Quandl::Operation::QDFormat::Node }
45
- its(:source_code){ should eq 'NSE' }
46
- its(:code){ should eq 'OIL' }
47
- its(:name){ should eq 'Oil India Limited' }
48
- its(:description){ should eq "Here is a description with multiple lines.\nThis is the second line." }
49
- its(:column_names){ should eq ['Date', 'Value', 'High', 'Low'] }
50
- its(:data){ should eq [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
51
- ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]] }
52
- end
53
- end
54
-
55
- end
@@ -1,41 +0,0 @@
1
- # encoding: utf-8
2
- require 'quandl/operation/qdformat'
3
- require 'spec_helper'
4
-
5
- describe Quandl::Operation::QDFormat::Node do
6
-
7
- let(:attributes) { {
8
- code: 'DATASET_CODE_2',
9
- source_code: 'SOURCE_CODE',
10
- name: 'Test Dataset Name 2',
11
- description: "Here is a description with multiple lines.\n This is the second line.",
12
- column_names: ['Date', 'Value', 'High', 'Low'],
13
- data: [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
14
- ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]],
15
- }}
16
-
17
- subject{ Quandl::Operation::QDFormat::Node.new(attributes) }
18
-
19
- its(:code){ should eq 'DATASET_CODE_2' }
20
- its(:source_code){ should eq 'SOURCE_CODE' }
21
- its(:name){ should eq 'Test Dataset Name 2' }
22
- its(:description){ should eq "Here is a description with multiple lines.\n This is the second line." }
23
- its(:column_names){ should eq ['Date', 'Value', 'High', 'Low'] }
24
- its(:data){ should eq [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
25
- ["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]] }
26
-
27
- its(:attributes){ should eq attributes }
28
-
29
- its(:to_qdf){ should eq %Q{source_code: SOURCE_CODE
30
- code: DATASET_CODE_2
31
- name: Test Dataset Name 2
32
- description: |-
33
- Here is a description with multiple lines.
34
- This is the second line.
35
- -
36
- Date,Value,High,Low
37
- 2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353
38
- 2013-11-19,10.039388096885814,,14.09718770934256
39
- }}
40
-
41
- end