Class: Teer::DataStore
- Inherits:
-
Object
- Object
- Teer::DataStore
- Defined in:
- lib/teer/data_store.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #as_json(options = nil) ⇒ Object
- #count ⇒ Object
- #eq(num) ⇒ Object
-
#eql(value) ⇒ Object
for equality checks.
- #first ⇒ Object
- #fourth ⇒ Object
- #group_count ⇒ Object
- #gt(num) ⇒ Object
-
#initialize(data, locale) ⇒ DataStore
constructor
A new instance of DataStore.
- #key ⇒ Object
- #keys ⇒ Object
- #last ⇒ Object
- #lt(num) ⇒ Object
- #map(*others) ⇒ Object
- #max ⇒ Object
- #min ⇒ Object
- #ne(num) ⇒ Object
- #pluck_by_value(value) ⇒ Object
- #second ⇒ Object
- #slice(key) ⇒ Object
- #slice_from(data_store, key) ⇒ Object
- #sort ⇒ Object
- #third ⇒ Object
- #to_s ⇒ Object
- #uniq ⇒ Object
- #value ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(data, locale) ⇒ DataStore
Returns a new instance of DataStore.
7 8 9 10 |
# File 'lib/teer/data_store.rb', line 7 def initialize(data, locale) @data = data @locale = locale end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
120 121 122 |
# File 'lib/teer/data_store.rb', line 120 def data @data end |
Instance Method Details
#[](i) ⇒ Object
48 49 50 |
# File 'lib/teer/data_store.rb', line 48 def [](i) VectorStore.new(@data[i], @locale) end |
#as_json(options = nil) ⇒ Object
122 123 124 |
# File 'lib/teer/data_store.rb', line 122 def as_json( = nil) @data.as_json() end |
#count ⇒ Object
36 37 38 |
# File 'lib/teer/data_store.rb', line 36 def count @data.count end |
#eq(num) ⇒ Object
80 81 82 |
# File 'lib/teer/data_store.rb', line 80 def eq(num) DataStore.new(@data.select { |a| a[-1] == num }, @locale) end |
#eql(value) ⇒ Object
for equality checks
116 117 118 |
# File 'lib/teer/data_store.rb', line 116 def eql(value) # for equality checks DataStore.new(@data.select { |a| a[1] == value }, @locale) end |
#first ⇒ Object
60 61 62 |
# File 'lib/teer/data_store.rb', line 60 def first VectorStore.new(@data[0], @locale) end |
#fourth ⇒ Object
72 73 74 |
# File 'lib/teer/data_store.rb', line 72 def fourth VectorStore.new(@data[3], @locale) end |
#group_count ⇒ Object
32 33 34 |
# File 'lib/teer/data_store.rb', line 32 def group_count DataStore.new(@data.transpose[0].each_with_object(Hash.new(0)) { |key, hsh| hsh[key] += 1 }.to_a, @locale) end |
#gt(num) ⇒ Object
84 85 86 |
# File 'lib/teer/data_store.rb', line 84 def gt(num) DataStore.new(@data.select { |a| a[-1] > num }, @locale) end |
#key ⇒ Object
12 13 14 |
# File 'lib/teer/data_store.rb', line 12 def key @data.transpose[0][0] end |
#keys ⇒ Object
20 21 22 |
# File 'lib/teer/data_store.rb', line 20 def keys VectorStore.new(@data.transpose[0], @locale) end |
#last ⇒ Object
76 77 78 |
# File 'lib/teer/data_store.rb', line 76 def last VectorStore.new(@data[-1], @locale) end |
#lt(num) ⇒ Object
88 89 90 |
# File 'lib/teer/data_store.rb', line 88 def lt(num) DataStore.new(@data.select { |a| a[-1] < num }, @locale) end |
#map(*others) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/teer/data_store.rb', line 105 def map(*others) @data.each_with_index.map do |a, i| yield(VectorStore.new(a, @locale), *(others || []).map { |other| VectorStore.new(other.data[i], @locale) }) end end |
#max ⇒ Object
40 41 42 |
# File 'lib/teer/data_store.rb', line 40 def max VectorStore.new(@data.max_by(&:last), @locale) end |
#min ⇒ Object
44 45 46 |
# File 'lib/teer/data_store.rb', line 44 def min VectorStore.new(@data.min_by(&:last), @locale) end |
#ne(num) ⇒ Object
92 93 94 |
# File 'lib/teer/data_store.rb', line 92 def ne(num) DataStore.new(@data.reject { |a| a[-1] == num }, @locale) end |
#pluck_by_value(value) ⇒ Object
56 57 58 |
# File 'lib/teer/data_store.rb', line 56 def pluck_by_value(value) DataStore.new(@data.select { |_, val| val == value }, @locale) end |
#second ⇒ Object
64 65 66 |
# File 'lib/teer/data_store.rb', line 64 def second VectorStore.new(@data[1], @locale) end |
#slice(key) ⇒ Object
96 97 98 |
# File 'lib/teer/data_store.rb', line 96 def slice(key) DataStore.new(@data.select { |a| a[0] == key }, @locale) end |
#slice_from(data_store, key) ⇒ Object
100 101 102 103 |
# File 'lib/teer/data_store.rb', line 100 def slice_from(data_store, key) idx = data_store.data.map { |a| a[0] == key } DataStore.new(@data.select.with_index { |_a, i| idx[i] }, @locale) end |
#sort ⇒ Object
52 53 54 |
# File 'lib/teer/data_store.rb', line 52 def sort DataStore.new(@data.sort_by(&:last).reverse, @locale) end |
#third ⇒ Object
68 69 70 |
# File 'lib/teer/data_store.rb', line 68 def third VectorStore.new(@data[2], @locale) end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/teer/data_store.rb', line 112 def to_s "DataStore.new(#{@data}, #{@locale})" end |
#uniq ⇒ Object
28 29 30 |
# File 'lib/teer/data_store.rb', line 28 def uniq VectorStore.new(@data.transpose[0].uniq, @locale) end |
#value ⇒ Object
16 17 18 |
# File 'lib/teer/data_store.rb', line 16 def value @data.transpose[1][0] end |
#values ⇒ Object
24 25 26 |
# File 'lib/teer/data_store.rb', line 24 def values VectorStore.new(@data.transpose[1], @locale) end |