Class: Nyaplot::Series

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nyaplot/data.rb

Instance Method Summary collapse

Constructor Details

#initialize(label, arr) ⇒ Series

Returns a new instance of Series.



186
187
188
189
# File 'lib/nyaplot/data.rb', line 186

def initialize(label, arr)
  @arr = arr
  @label = label
end

Instance Method Details

#eachObject



191
192
193
194
195
# File 'lib/nyaplot/data.rb', line 191

def each
  @arr.each do |item|
    yield item
  end
end

#labelObject



223
224
225
# File 'lib/nyaplot/data.rb', line 223

def label
  @label
end

#maxObject



201
202
203
# File 'lib/nyaplot/data.rb', line 201

def max
  @arr.max
end

#minObject



197
198
199
# File 'lib/nyaplot/data.rb', line 197

def min
  @arr.min
end

#to_aObject



219
220
221
# File 'lib/nyaplot/data.rb', line 219

def to_a
  @arr
end

#to_html(threshold = 15) ⇒ Object



205
206
207
208
209
210
211
212
213
# File 'lib/nyaplot/data.rb', line 205

def to_html(threshold=15)
  html = '<table><tr><th>' + label.to_s + '</th></tr>>'
  @arr.each_with_index do |el,i|
    next if threshold < i && i < @arr.length-1
    content = i == threshold ? '...' : el.to_s
    html.concat('<tr><td>' + content  + '</td></tr>')
  end
  html += '</table>'
end

#to_json(*args) ⇒ Object



215
216
217
# File 'lib/nyaplot/data.rb', line 215

def to_json(*args)
  @arr.to_json
end