quandl_format 0.0.1 → 0.0.2
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 +4 -4
- data/UPGRADE.md +5 -0
- data/lib/quandl/format/dump.rb +6 -12
- data/lib/quandl/format/node.rb +32 -10
- data/lib/quandl/format/version.rb +1 -1
- data/spec/lib/quandl/format/node_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88de117fd0aaa74d5aed80b7d34a77200409fa6e
|
4
|
+
data.tar.gz: 30fbd84655aedd481be97a672725aa173116bff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9809fccf8d818791f6b000d44918a525836d32c3227f4156bd5f7fe098240e42e7179745ee78ffc411604f8164429760670e9da8e0f02e778d42c9a5e7f23b08
|
7
|
+
data.tar.gz: 0fc2a754ce3f08d0fd4b54066ab059623e53e3af8b112255188a42f60a54e3af0cfd00b613851a4d9902a91287129dde92dfe1320012d334bca9efa5210d0545
|
data/UPGRADE.md
CHANGED
data/lib/quandl/format/dump.rb
CHANGED
@@ -3,8 +3,6 @@ module Format
|
|
3
3
|
|
4
4
|
class Dump
|
5
5
|
|
6
|
-
ATTRIBUTES = [ :source_code, :code, :name, :description, :private, :display_url ]
|
7
|
-
|
8
6
|
class << self
|
9
7
|
|
10
8
|
def nodes(*args)
|
@@ -24,24 +22,20 @@ class Dump
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def to_qdf
|
27
|
-
[
|
28
|
-
|
25
|
+
[
|
26
|
+
meta_attributes,
|
29
27
|
column_names,
|
30
28
|
data
|
31
29
|
].compact.join
|
32
30
|
end
|
33
31
|
|
34
|
-
def
|
35
|
-
|
36
|
-
name = name.to_s
|
37
|
-
memo[name] = node.send(name) if node.respond_to?(name) && node.send(name).present?
|
38
|
-
memo
|
39
|
-
end
|
40
|
-
attrs.to_yaml[4..-1]
|
32
|
+
def meta_attributes
|
33
|
+
node.meta_attributes.stringify_keys.to_yaml[4..-1] + "-\n"
|
41
34
|
end
|
42
35
|
|
43
36
|
def data
|
44
|
-
data = node.data
|
37
|
+
data = node.data
|
38
|
+
data = data.collect(&:to_csv).join if data.is_a?(Array) && data.first.respond_to?(:to_csv)
|
45
39
|
data = data.to_csv if data.respond_to?(:to_csv)
|
46
40
|
data
|
47
41
|
end
|
data/lib/quandl/format/node.rb
CHANGED
@@ -1,7 +1,25 @@
|
|
1
1
|
class Quandl::Format::Node
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
META_ATTRIBUTES = :source_code, :code, :name, :description, :private, :display_url
|
4
|
+
DATA_ATTRIBUTES = :column_names, :data
|
5
|
+
|
6
|
+
attr_accessor *( META_ATTRIBUTES + DATA_ATTRIBUTES )
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def attribute_names
|
11
|
+
@attribute_names ||= meta_attribute_names + data_attribute_names
|
12
|
+
end
|
13
|
+
|
14
|
+
def meta_attribute_names
|
15
|
+
META_ATTRIBUTES
|
16
|
+
end
|
17
|
+
|
18
|
+
def data_attribute_names
|
19
|
+
DATA_ATTRIBUTES
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
5
23
|
|
6
24
|
def initialize(attrs)
|
7
25
|
assign_attributes(attrs)
|
@@ -13,14 +31,6 @@ class Quandl::Format::Node
|
|
13
31
|
end
|
14
32
|
end
|
15
33
|
|
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
34
|
def full_code=(value)
|
25
35
|
value = value.split('/')
|
26
36
|
self.source_code = value[0]
|
@@ -47,5 +57,17 @@ class Quandl::Format::Node
|
|
47
57
|
def to_qdf
|
48
58
|
Quandl::Format::Dump.node(self)
|
49
59
|
end
|
60
|
+
|
61
|
+
def meta_attributes
|
62
|
+
self.class.meta_attribute_names.inject({}){|m,k| m[k] = self.send(k); m }
|
63
|
+
end
|
64
|
+
|
65
|
+
def attributes
|
66
|
+
self.class.attribute_names.inject({}){|m,k| m[k] = self.send(k); m }
|
67
|
+
end
|
68
|
+
|
69
|
+
def inspect
|
70
|
+
"<##{self.class.name} #{meta_attributes.to_s} >"
|
71
|
+
end
|
50
72
|
|
51
73
|
end
|
@@ -9,6 +9,8 @@ describe Quandl::Format::Node do
|
|
9
9
|
name: 'Test Dataset Name 2',
|
10
10
|
description: "Here is a description with multiple lines.\n This is the second line.",
|
11
11
|
column_names: ['Date', 'Value', 'High', 'Low'],
|
12
|
+
private: false,
|
13
|
+
display_url: 'http://test.com/',
|
12
14
|
data: [["2013-11-20", "9.99470588235294", "11.003235294117646", "14.00164705882353"],
|
13
15
|
["2013-11-19", "10.039388096885814", nil, "14.09718770934256"]],
|
14
16
|
}}
|
@@ -31,6 +33,8 @@ name: Test Dataset Name 2
|
|
31
33
|
description: |-
|
32
34
|
Here is a description with multiple lines.
|
33
35
|
This is the second line.
|
36
|
+
private: false
|
37
|
+
display_url: http://test.com/
|
34
38
|
-
|
35
39
|
Date,Value,High,Low
|
36
40
|
2013-11-20,9.99470588235294,11.003235294117646,14.00164705882353
|