quandl_format 0.3.0 → 0.4.0

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: d3736904b3e0d1c5ee9b90ebfaca235563775f56
4
- data.tar.gz: f12745b06559794e379a999280cb4e6c28ea01ae
3
+ metadata.gz: 7189ebd211ad89843f508a2c8f250f5fa861c699
4
+ data.tar.gz: 3eb2d90fab9ec9ded6afcfd1a9f37f8aabd4103d
5
5
  SHA512:
6
- metadata.gz: 3537467133b0cb0f5b89732974bc034b2c5198970d2b215789a53d2a714ce63a8d09665b0d0afcd6a8b424404e07e7cdb199f34f3fe187ab8ec621ad4facc1d0
7
- data.tar.gz: a4ad1d3c31abd11d3ee0a493f1e3126f28db56d6b7d124aec9825b48465b046ce3edabbd41aa596f71e88c89a51d8575f39a3695c49fdd80c423c3a17fbfbfc9
6
+ metadata.gz: 21c433bfc641a0d32700d5797c7f7640e210f134d12aa7b7d0d39b72441280766fa80744040475062fd758a550245c1c2d1e3811239c44deb25ff130231f6f4a
7
+ data.tar.gz: 3eda4b6c2e8ec8cde35b9935948bd7295a485b6431bdcf28bff20242d11414a17c161597da6501ee134dafeacfa243059746242ca4fc620d2cc66fc3f7a80f5f
data/README.md CHANGED
@@ -1,2 +1,53 @@
1
1
  # Quandl::Format
2
2
 
3
+ ## Purpose
4
+
5
+ Load and dump [quandl data format](http://www.quandl.com/help/toolbelt#Quandl-Flavored-CSV).
6
+
7
+
8
+ ## Installation
9
+
10
+ ```ruby
11
+ gem 'quandl_format'
12
+ ```
13
+
14
+
15
+ ## Configuration
16
+
17
+ Add this to your Rakefile:
18
+
19
+ ```ruby
20
+ require 'quandl/format'
21
+ ```
22
+
23
+
24
+ ## Usage
25
+
26
+
27
+ #### Load
28
+
29
+ ```ruby
30
+ # open a file
31
+ file = File.open("spec/fixtures/data/annual.qdf")
32
+ # read each line of the file until a dataset node has been built
33
+ # pass each dataset node to the block for manipulation
34
+ Quandl::Format::Dataset.each_line(file) do |dataset|
35
+ puts "full_code: #{dataset.full_code}"
36
+ puts "first_line_of_data: #{dataset.data.first.to_s}"
37
+ end
38
+ ```
39
+
40
+
41
+ #### Dump
42
+
43
+ ```ruby
44
+ # load the file as a collection of Dataset instances
45
+ datasets = Quandl::Format::Dataset.load_from_file("spec/fixtures/data/annual.qdf")
46
+ # make some changes
47
+ dataset = datasets.first
48
+ dataset.code = 'NEW_CODE'
49
+ # dump the collection as QDF
50
+ puts Quandl::Format::Dataset.dump( [dataset] )
51
+ ```
52
+
53
+
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ end
19
19
  require 'quandl/utility/rake_tasks'
20
20
  Quandl::Utility::Tasks.configure do |c|
21
21
  c.name = 'quandl_format'
22
+ c.tag_prefix = 'v'
22
23
  c.version_path = 'VERSION'
23
24
  c.changelog_path = 'UPGRADE.md'
24
25
  c.changelog_matching = ['^QUGC','^WIKI']
data/UPGRADE.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.0
2
+
3
+ * QUGC-123 Use client#valid? since it has been refactored to check everything.
4
+
5
+
6
+
1
7
  ## 0.3.0
2
8
 
3
9
  * QUGC-104 bump gems to get onboard with new validations and error handling
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -4,6 +4,7 @@ module Client
4
4
  class Dataset
5
5
 
6
6
  def to_qdf
7
+ return if !exists? && status != 0
7
8
  Quandl::Format::Dataset.new( qdf_attributes ).to_qdf
8
9
  end
9
10
 
@@ -0,0 +1,15 @@
1
+ module Quandl
2
+ module Client
3
+ class Superset
4
+
5
+ def to_qdf
6
+ return unless exists?
7
+ out = attributes.stringify_keys.to_hash.to_yaml[4..-1]
8
+ out += Quandl::Format::Superset::Node.syntax[:end_of_node]
9
+ out += "\n"
10
+ out
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,87 @@
1
+ module Quandl
2
+ module Format
3
+ class Abstract
4
+ class Node
5
+
6
+ cattr_accessor :syntax, instance_reader: true
7
+
8
+ self.syntax = {
9
+ comment: '#',
10
+ end_of_node: '-',
11
+ }
12
+
13
+ attr_accessor :block, :line, :lines
14
+
15
+ def initialize(*args)
16
+ # options
17
+ opts = args.extract_options!.symbolize_keys!
18
+ # assign options
19
+ self.line = opts[:line].to_i if opts[:line].present?
20
+ self.block = opts[:block]
21
+ end
22
+
23
+ def add(value)
24
+ increment_line
25
+ # clean the value
26
+ value = clean(value)
27
+ # does this mark the end of the node?
28
+ return close if end_of_node?(value)
29
+ # handle the new line
30
+ add_to_lines(value)
31
+ # onwards
32
+ self
33
+ end
34
+
35
+ def close
36
+ # pass the node to the block
37
+ block.call(self) unless lines.blank?
38
+ # return a new node
39
+ self.class.new( line: line, block: block )
40
+ end
41
+
42
+ def line
43
+ @line ||= 0
44
+ end
45
+
46
+ def lines
47
+ @lines ||= []
48
+ end
49
+
50
+ def as_json
51
+ YAML.load(lines.join("\n"))
52
+ end
53
+
54
+ protected
55
+
56
+ def increment_line
57
+ self.line += 1
58
+ end
59
+
60
+ def add_to_lines(value)
61
+ # ignore comments
62
+ return false if comment?(value)
63
+ # otherwise append the value
64
+ lines << value
65
+ end
66
+
67
+ def end_of_node?(value)
68
+ syntax_matches?( :end_of_node, value )
69
+ end
70
+
71
+ def comment?(value)
72
+ value.blank? || syntax_matches?(:comment, value)
73
+ end
74
+
75
+ def syntax_matches?(key, value)
76
+ syn = syntax[key]
77
+ value.to_s[ 0..(syn.length) ] == syn
78
+ end
79
+
80
+ def clean(value)
81
+ value.to_s.strip.rstrip
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,53 @@
1
+ require 'quandl/format/abstract/node'
2
+
3
+ module Quandl
4
+ module Format
5
+ class Abstract
6
+
7
+ class << self
8
+
9
+ def load(interface)
10
+ output = []
11
+ foreach(interface){|n| output << n }
12
+ output
13
+ end
14
+
15
+ def foreach(interface, &block)
16
+ each_line_as_node(interface) do |node|
17
+ call_and_catch_block(node, &block)
18
+ end
19
+ end
20
+
21
+ def each_line_as_node(interface, &block)
22
+ # initialize an empty node
23
+ node = self::Node.new( block: block )
24
+ # for each_line of the interface
25
+ interface.each_line do |line|
26
+ # add the line to the node
27
+ node = node.add( line )
28
+ end
29
+ # we're done
30
+ node.close
31
+ end
32
+
33
+
34
+ protected
35
+
36
+ def call_and_catch_block(node, &block)
37
+ # convert the node to an instance of superset
38
+ node = before_call(node)
39
+ # pass the superset to the block
40
+ block.call( node )
41
+ rescue Exception => error
42
+ block.call( error )
43
+ end
44
+
45
+ def before_call(node)
46
+ node
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -47,7 +47,7 @@ module Client
47
47
  protected
48
48
 
49
49
  def client_should_be_valid!
50
- if !client.valid_with_server?
50
+ if !client.valid?
51
51
  client.errors.each{|err, value| self.errors.add( err, value ) }
52
52
  return false
53
53
  end
@@ -1,3 +1,5 @@
1
+ require 'quandl/client/dataset/to_qdf'
2
+
1
3
  module Quandl
2
4
  module Format
3
5
 
@@ -0,0 +1,12 @@
1
+ module Quandl
2
+ module Format
3
+ class Superset
4
+
5
+ class Node < Quandl::Format::Abstract::Node
6
+
7
+ self.syntax[:end_of_node] = '---'
8
+
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'quandl/client/superset/to_qdf'
2
+
3
+ module Quandl
4
+ module Format
5
+
6
+ class Superset < Quandl::Format::Abstract
7
+
8
+ require 'quandl/format/superset/node'
9
+
10
+ def self.before_call(node)
11
+ Quandl::Client::Superset.new( node.as_json )
12
+ end
13
+
14
+ end
15
+ end
16
+ end
data/lib/quandl/format.rb CHANGED
@@ -15,8 +15,9 @@ require "active_support/core_ext/object"
15
15
  require 'quandl/error/column_count_mismatch'
16
16
  require 'quandl/error/unknown_attribute'
17
17
 
18
+ require 'quandl/format/abstract'
18
19
  require 'quandl/format/dataset'
19
- require 'quandl/client/dataset/to_qdf'
20
+ require 'quandl/format/superset'
20
21
 
21
22
  module Quandl
22
23
  module Format
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_runtime_dependency "quandl_client", "~> 2.6"
20
+ s.add_runtime_dependency "quandl_client", "~> 2.7"
21
21
 
22
22
  s.add_development_dependency "rake", "~> 10.0"
23
23
  s.add_development_dependency "rspec", "~> 2.13"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: quandl_client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
19
+ version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '2.6'
26
+ version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -153,14 +153,19 @@ files:
153
153
  - VERSION
154
154
  - examples/load.rb
155
155
  - lib/quandl/client/dataset/to_qdf.rb
156
+ - lib/quandl/client/superset/to_qdf.rb
156
157
  - lib/quandl/error/column_count_mismatch.rb
157
158
  - lib/quandl/error/unknown_attribute.rb
158
159
  - lib/quandl/format.rb
160
+ - lib/quandl/format/abstract.rb
161
+ - lib/quandl/format/abstract/node.rb
159
162
  - lib/quandl/format/dataset.rb
160
163
  - lib/quandl/format/dataset/attributes.rb
161
164
  - lib/quandl/format/dataset/client.rb
162
165
  - lib/quandl/format/dataset/dump.rb
163
166
  - lib/quandl/format/dataset/load.rb
167
+ - lib/quandl/format/superset.rb
168
+ - lib/quandl/format/superset/node.rb
164
169
  - lib/quandl/format/version.rb
165
170
  - quandl_format.gemspec
166
171
  - spec/config/client.rb