quandl_cassinatra 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,15 +40,15 @@ module Searchable
40
40
  delegate *Data::Table.forwardable_methods, to: :data_table
41
41
  end
42
42
 
43
- search_scope :limit, ->(amount) { where( limit: amount.to_i ) }
43
+ search_scope :limit, ->(amount) { where( limit: amount.to_i ); }
44
44
  search_scope :offset, ->(amount) { where( offset: amount.to_i ) }
45
45
  search_scope :accuracy, ->(amount) { where( accuracy: amount.to_i ) }
46
46
  search_scope :column, ->(index) { where( column: index.to_i ) }
47
47
  search_scope :order, ->(dir) { where( order: (dir.to_sym == :asc) ? 'asc' : 'desc' ) }
48
48
  search_scope :trim_start, ->(date) { where( trim_start: format_trim_date(date, :start)) }
49
49
  search_scope :trim_end, ->(date) { where( trim_end: format_trim_date(date, :end)) }
50
- search_scope :transform, ->(value) { where( transform: value.to_s ) if self.class.parent.valid_transformation?(value.to_sym) }
51
50
  search_scope :with_id, ->(value) { where( id: value.to_i )}
51
+ search_scope :transform, ->(value) { where( transform: value.to_sym ) if self.class.parent.valid_transformation?(value.to_sym) }
52
52
 
53
53
  search_scope :collapse, ->(name){
54
54
  # set collapse
@@ -58,6 +58,22 @@ module Searchable
58
58
  trim_end(trim_end) if trim_end
59
59
  }
60
60
 
61
+ # wrap limit, offset, and order with row
62
+ search_scope :row, ->(value){
63
+ # ensure integer
64
+ value = value.to_i
65
+ # negative value implies ascending order
66
+ if value < 0
67
+ order(:asc)
68
+ offset( ( value * -1 ) - 1 )
69
+ limit( 1 )
70
+ else
71
+ order(:desc)
72
+ offset( value )
73
+ limit(1)
74
+ end
75
+ }
76
+
61
77
  search_helper :format_trim_date, ->( date, start_or_end ){
62
78
  date = Date.jd(date) if date.is_a?(Integer)
63
79
  date = Date.parse(date) if date.is_a?(String)
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Cassinatra
3
- VERSION = '0.0.10'
3
+ VERSION = '0.0.11'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_cassinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: