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
5 6 7 8 |
# File 'lib/teer/data_store.rb', line 5 def initialize(data, locale) @data = data @locale = locale end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
118 119 120 |
# File 'lib/teer/data_store.rb', line 118 def data @data end |
Instance Method Details
#[](i) ⇒ Object
46 47 48 |
# File 'lib/teer/data_store.rb', line 46 def [](i) VectorStore.new(@data[i], @locale) end |
#as_json(options = nil) ⇒ Object
120 121 122 |
# File 'lib/teer/data_store.rb', line 120 def as_json( = nil) @data.as_json() end |
#count ⇒ Object
34 35 36 |
# File 'lib/teer/data_store.rb', line 34 def count @data.count end |
#eq(num) ⇒ Object
78 79 80 |
# File 'lib/teer/data_store.rb', line 78 def eq(num) DataStore.new(@data.select { |a| a[-1] == num }, @locale) end |
#eql(value) ⇒ Object
for equality checks
114 115 116 |
# File 'lib/teer/data_store.rb', line 114 def eql(value) # for equality checks DataStore.new(@data.select { |a| a[1] == value }, @locale) end |
#first ⇒ Object
58 59 60 |
# File 'lib/teer/data_store.rb', line 58 def first VectorStore.new(@data[0], @locale) end |
#fourth ⇒ Object
70 71 72 |
# File 'lib/teer/data_store.rb', line 70 def fourth VectorStore.new(@data[3], @locale) end |
#group_count ⇒ Object
30 31 32 |
# File 'lib/teer/data_store.rb', line 30 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
82 83 84 |
# File 'lib/teer/data_store.rb', line 82 def gt(num) DataStore.new(@data.select { |a| a[-1] > num }, @locale) end |
#key ⇒ Object
10 11 12 |
# File 'lib/teer/data_store.rb', line 10 def key @data.transpose[0][0] end |
#keys ⇒ Object
18 19 20 |
# File 'lib/teer/data_store.rb', line 18 def keys VectorStore.new(@data.transpose[0], @locale) end |
#last ⇒ Object
74 75 76 |
# File 'lib/teer/data_store.rb', line 74 def last VectorStore.new(@data[-1], @locale) end |
#lt(num) ⇒ Object
86 87 88 |
# File 'lib/teer/data_store.rb', line 86 def lt(num) DataStore.new(@data.select { |a| a[-1] < num }, @locale) end |
#map(*others) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/teer/data_store.rb', line 103 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
38 39 40 |
# File 'lib/teer/data_store.rb', line 38 def max VectorStore.new(@data.max_by(&:last), @locale) end |
#min ⇒ Object
42 43 44 |
# File 'lib/teer/data_store.rb', line 42 def min VectorStore.new(@data.min_by(&:last), @locale) end |
#ne(num) ⇒ Object
90 91 92 |
# File 'lib/teer/data_store.rb', line 90 def ne(num) DataStore.new(@data.reject { |a| a[-1] == num }, @locale) end |
#pluck_by_value(value) ⇒ Object
54 55 56 |
# File 'lib/teer/data_store.rb', line 54 def pluck_by_value(value) DataStore.new(@data.select { |_, val| val == value }, @locale) end |
#second ⇒ Object
62 63 64 |
# File 'lib/teer/data_store.rb', line 62 def second VectorStore.new(@data[1], @locale) end |
#slice(key) ⇒ Object
94 95 96 |
# File 'lib/teer/data_store.rb', line 94 def slice(key) DataStore.new(@data.select { |a| a[0] == key }, @locale) end |
#slice_from(data_store, key) ⇒ Object
98 99 100 101 |
# File 'lib/teer/data_store.rb', line 98 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
50 51 52 |
# File 'lib/teer/data_store.rb', line 50 def sort DataStore.new(@data.sort_by(&:last).reverse, @locale) end |
#third ⇒ Object
66 67 68 |
# File 'lib/teer/data_store.rb', line 66 def third VectorStore.new(@data[2], @locale) end |
#to_s ⇒ Object
110 111 112 |
# File 'lib/teer/data_store.rb', line 110 def to_s "DataStore.new(#{@data}, #{@locale})" end |
#uniq ⇒ Object
26 27 28 |
# File 'lib/teer/data_store.rb', line 26 def uniq VectorStore.new(@data.transpose[0].uniq, @locale) end |
#value ⇒ Object
14 15 16 |
# File 'lib/teer/data_store.rb', line 14 def value @data.transpose[1][0] end |
#values ⇒ Object
22 23 24 |
# File 'lib/teer/data_store.rb', line 22 def values VectorStore.new(@data.transpose[1], @locale) end |