quandl_cassinatra 0.1.7 → 0.1.8

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: dae7b31b51fc6f62d2c609056fbff56c11a85097
4
- data.tar.gz: fdf372ce2162393f3004283773b8b71bdac6ef18
3
+ metadata.gz: 45a95dc8da2c6c36d90fab270ae451dad6664cbb
4
+ data.tar.gz: 4aa4b14387f7a9cefa3497e0ebb7e3d4fc072e0d
5
5
  SHA512:
6
- metadata.gz: e84b06ef67562343c3612f615e51ce9c7386c53026efba232e9e365db6e703148f767bc149ffa74afa3f3be48786afd29f86de5fe9293a734734cef5d420e4af
7
- data.tar.gz: 35bec6ab3b0b0dabeb9a61af543e58129e2e50171e17c77a453eedc71228ed1561d78c8cfd9a9aa28a9a7cd6a371e0e9c07146035f8b77ae551415b32c95f866
6
+ metadata.gz: 033f0adbf5d98363b3841dc6b0c9aa820fa87c8fdf405d8bcf5375b101688025c8159a6c2f368b826c8f07bd4ac27328fba3621d18a441bf3d7c5e318fe7f6d3
7
+ data.tar.gz: 65ec2ad1d5fa2c5ef4cf0bfb5ce49a0aab7341e52b288e45d250b6ae166a00e78a12d9abead16936f506f77b8ca98cf8edc0b00b8aa811b716a90c657183143f
@@ -22,6 +22,10 @@ module Properties
22
22
  true
23
23
  end
24
24
 
25
+ def save!
26
+ save
27
+ end
28
+
25
29
  def error_messages
26
30
  valid?
27
31
  errors_client.deep_merge(errors_server).deep_merge(errors_params)
@@ -8,7 +8,7 @@ module Search
8
8
  included do
9
9
 
10
10
  include ScopeComposer::Model
11
-
11
+
12
12
  scope_composer_for :search
13
13
 
14
14
  search_helper :all, ->{ connection.where(attributes).fetch }
@@ -0,0 +1,8 @@
1
+ class String
2
+
3
+ def numeric?
4
+ return true if self =~ /^\d+$/
5
+ true if Float(self) rescue false
6
+ end
7
+
8
+ end
@@ -0,0 +1 @@
1
+ require "quandl/cassinatra/core_ext/string"
@@ -40,11 +40,11 @@ module Searchable
40
40
  delegate *Data::Table.forwardable_methods, to: :data_table
41
41
  end
42
42
 
43
- search_scope :row, ->(v){ where( row: v.to_i ) }
44
- search_scope :limit, ->(v){ where( limit: v.to_i ) }
45
- search_scope :offset, ->(v){ where( offset: v.to_i ) }
46
- search_scope :accuracy, ->(v){ where( accuracy: v.to_i ) }
47
- search_scope :column, ->(index) { where( column: index.to_i ) }
43
+ search_scope :row, ->(v) { where( row: v.to_i ) }
44
+ search_scope :limit, ->(v) { where( limit: v.to_i ) }
45
+ search_scope :offset, ->(v) { where( offset: v.to_i ) }
46
+ search_scope :accuracy, ->(v) { where( accuracy: v.to_i ) }
47
+ search_scope :column, ->(v) { where( column: v.to_i ) }
48
48
  search_scope :order, ->(dir) { where( order: (dir.to_sym == :asc) ? 'asc' : 'desc' ) }
49
49
  search_scope :trim_start, ->(date) { where( trim_start: format_trim_date(date, :start)) }
50
50
  search_scope :trim_end, ->(date) { where( trim_end: format_trim_date(date, :end)) }
@@ -60,6 +60,7 @@ module Searchable
60
60
  }
61
61
 
62
62
  search_helper :format_trim_date, ->( date, start_or_end ){
63
+ date = Date.jd(date.to_i) if date.kind_of?(String) && date.numeric?
63
64
  date = Date.jd(date) if date.is_a?(Integer)
64
65
  date = Date.parse(date) if date.is_a?(String)
65
66
  date = date.send("#{start_or_end}_of_frequency", collapse) if collapse.present?
@@ -14,7 +14,7 @@ class Dataset
14
14
  delegate :columns_count, :created_at, :frequency, :rows_count, :type, :updated_at, to: :dataset_attribute
15
15
 
16
16
  def data_table
17
- Data::Table.new( self.data || [] )
17
+ @data_table ||= Data::Table.new( self.data || [] )
18
18
  end
19
19
  def data_table=(value)
20
20
  self.data = Data::Table.new(value).to_csv
@@ -7,8 +7,20 @@ class Multiset
7
7
  include Model::Dataset::Searchable
8
8
  include Concerns::Properties
9
9
 
10
+
11
+ search_helper :to_dataset, -> { dataset }
10
12
  search_helper :dataset, -> { find('multiset') }
11
- search_scope :columns
13
+ search_scope :columns, -> (v) { where( columns: format_columns(v) ) }
14
+
15
+ search_helper :format_columns, ->(cols){
16
+ cols.split(',').collect do |column|
17
+ id_position = column.split('.')
18
+ id = id_position.first.to_i
19
+ position = id_position.last.to_i
20
+ position = position - 1 if position > 0
21
+ "#{id}.#{position}"
22
+ end.join(',')
23
+ }
12
24
 
13
25
  attributes :id, :column_ids, :data
14
26
 
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Cassinatra
3
- VERSION = '0.1.7'
3
+ VERSION = '0.1.8'
4
4
  end
5
5
  end
@@ -12,6 +12,8 @@ require 'quandl/her/patch'
12
12
  require 'scope_composer'
13
13
  require "quandl/data"
14
14
 
15
+ require "quandl/cassinatra/core_ext"
16
+
15
17
  require 'quandl/cassinatra/concerns'
16
18
  require 'quandl/cassinatra/her'
17
19
  require 'quandl/cassinatra/model'
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_development_dependency "rake", "~> 10.0"
21
21
  s.add_development_dependency "rspec", "~> 2.13"
22
+ s.add_development_dependency "factory_girl", "~> 4.2.0"
22
23
  s.add_development_dependency "fivemat", "~> 1.2"
23
24
  s.add_development_dependency "pry"
24
25
 
@@ -27,6 +28,6 @@ Gem::Specification.new do |s|
27
28
  s.add_runtime_dependency "yajl-ruby", "~> 1.1.0"
28
29
  s.add_runtime_dependency 'json', '~> 1.7.7'
29
30
 
30
- s.add_runtime_dependency "quandl_data", ">= 0.1.7"
31
+ s.add_runtime_dependency "quandl_data", ">= 0.1.8"
31
32
  s.add_runtime_dependency "scope_composer", ">= 0.1.0"
32
33
  end
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :dataset do
4
+ sequence(:id) { |n| (Time.now.to_f * 1000).to_i + n }
5
+ data_table{ Quandl::Data::Random.table( rows: 730, columns: 3, nils: false ) }
6
+ end
7
+
8
+ end
@@ -1,11 +1,58 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Quandl::Cassinatra::Dataset do
5
- subject { Quandl::Cassinatra::Dataset.new }
4
+ describe Dataset do
5
+ subject { Dataset.new }
6
6
 
7
7
  it { should respond_to :columns_count }
8
8
  it { should respond_to :data }
9
9
  it { should respond_to :data_table }
10
10
 
11
+ context "create" do
12
+
13
+ subject{ build(:dataset) }
14
+
15
+ it "should have data" do
16
+ subject.data_table.count.should eq 730
17
+ end
18
+
19
+ it "should have four columns" do
20
+ subject.data_table[0].count.should eq 4
21
+ end
22
+
23
+ it "should create the dataset" do
24
+ subject.save
25
+ Dataset.find(subject.id).data.count.should eq 730
26
+ end
27
+
28
+ end
29
+
30
+ context "searchable" do
31
+
32
+ describe "trim_start" do
33
+
34
+ it "should accept date" do
35
+ date = Date.today
36
+ Dataset.trim_start(date).attributes[:trim_start].should eq Date.today.jd
37
+ end
38
+
39
+ it "should accept string date" do
40
+ date = Date.today.to_s
41
+ Dataset.trim_start(date).attributes[:trim_start].should eq Date.today.jd
42
+ end
43
+
44
+ it "should accept string julian date" do
45
+ date = Date.today.jd.to_s
46
+ Dataset.trim_start(date).attributes[:trim_start].should eq Date.today.jd
47
+ end
48
+
49
+ it "should accept integer" do
50
+ date = Date.today.jd
51
+ Dataset.trim_start(date).attributes[:trim_start].should eq Date.today.jd
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
11
58
  end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Multiset do
5
+ let(:d1){ create(:dataset, data_table: Quandl::Data::Random.table( rows: 10, columns: 4, nils: false ) ) }
6
+ let(:d2){ create(:dataset, data_table: Quandl::Data::Random.table( rows: 10, columns: 4, nils: false ) ) }
7
+
8
+ it "should retrieve the requested columns" do
9
+ m = Multiset.columns("#{d1.id.to_i}.0,#{d2.id.to_i}.0").to_dataset
10
+ m.data_table[0][1].should eq d1.data_table[0][1]
11
+ m.data_table[0][2].should eq d2.data_table[0][1]
12
+ end
13
+
14
+ it "should retrieve the requested columns" do
15
+ m = Multiset.columns("#{d2.id.to_i}.1,#{d1.id.to_i}.1").to_dataset
16
+ m.data_table[0][1].should eq d2.data_table[0][1]
17
+ m.data_table[0][2].should eq d1.data_table[0][1]
18
+ end
19
+
20
+ it "should be in the right order" do
21
+ m = Multiset.columns("#{d2.id.to_i}.1,#{d1.id.to_i}.1,#{d2.id.to_i}.3,#{d1.id.to_i}.2").to_dataset
22
+ c1 = Dataset.find(d1.id).column_ids
23
+ c2 = Dataset.find(d2.id).column_ids
24
+ requested_order = [ c2[0], c1[0], c2[2], c1[1] ]
25
+ m.column_ids.should eq requested_order
26
+ end
27
+
28
+ it "should retrieve the requested columns" do
29
+ m = Multiset.columns("#{d2.id.to_i}.1,#{d1.id.to_i}.1,#{d2.id.to_i}.3,#{d1.id.to_i}.2").to_dataset
30
+ m.data_table[0][1].should eq d2.data_table[0][1]
31
+ m.data_table[0][2].should eq d1.data_table[0][1]
32
+ m.data_table[0][3].should eq d2.data_table[0][3]
33
+ m.data_table[0][4].should eq d1.data_table[0][2]
34
+ end
35
+
36
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,19 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
2
 
3
3
  require "rspec"
4
- require "quandl/cassinatra"
4
+ require 'pry'
5
+ require 'factory_girl'
6
+
7
+ factory_dir = File.join( File.dirname(__FILE__), 'factories/**/*.rb' )
8
+ Dir.glob( factory_dir ).each{|f| require(f); puts f }
9
+
10
+ RSpec.configure do |config|
11
+ config.include FactoryGirl::Syntax::Methods
12
+ end
13
+
14
+
15
+ # LOAD GEM
16
+
17
+ require "quandl/cassinatra"
18
+ Quandl::Cassinatra.use 'http://192.168.33.10:8983/wikiposit_cassandra/'
19
+ include Quandl::Cassinatra
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_cassinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
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-07-23 00:00:00.000000000 Z
11
+ date: 2013-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_girl
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 4.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 4.2.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: fivemat
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +142,14 @@ dependencies:
128
142
  requirements:
129
143
  - - '>='
130
144
  - !ruby/object:Gem::Version
131
- version: 0.1.7
145
+ version: 0.1.8
132
146
  type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - '>='
137
151
  - !ruby/object:Gem::Version
138
- version: 0.1.7
152
+ version: 0.1.8
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: scope_composer
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +184,8 @@ files:
170
184
  - lib/quandl/cassinatra/concerns.rb
171
185
  - lib/quandl/cassinatra/concerns/properties.rb
172
186
  - lib/quandl/cassinatra/concerns/search.rb
187
+ - lib/quandl/cassinatra/core_ext.rb
188
+ - lib/quandl/cassinatra/core_ext/string.rb
173
189
  - lib/quandl/cassinatra/her.rb
174
190
  - lib/quandl/cassinatra/model.rb
175
191
  - lib/quandl/cassinatra/model/dataset.rb
@@ -179,7 +195,9 @@ files:
179
195
  - lib/quandl/cassinatra/version.rb
180
196
  - lib/quandl/her/patch.rb
181
197
  - quandl_cassinatra.gemspec
198
+ - spec/factories/dataset.rb
182
199
  - spec/quandl/cassinatra/dataset_spec.rb
200
+ - spec/quandl/cassinatra/multiset_spec.rb
183
201
  - spec/spec_helper.rb
184
202
  homepage: http://blake.hilscher.ca/
185
203
  licenses:
@@ -206,5 +224,7 @@ signing_key:
206
224
  specification_version: 4
207
225
  summary: Cassinatra rest orm.
208
226
  test_files:
227
+ - spec/factories/dataset.rb
209
228
  - spec/quandl/cassinatra/dataset_spec.rb
229
+ - spec/quandl/cassinatra/multiset_spec.rb
210
230
  - spec/spec_helper.rb