Skip to content

Commit

Permalink
Add formatador and nyaplot to runtime dependencies and implement Data…
Browse files Browse the repository at this point in the history
…Frame#to_s and Series#to_s
  • Loading branch information
domitry committed Nov 1, 2014
1 parent 9fa33b1 commit 374892c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/mikon/core/dataframe.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'securerandom'
require 'formatador'
require 'json'
require 'csv'

Expand Down Expand Up @@ -182,6 +183,18 @@ def to_html(threshold=50)
html += "</table>"
end

def to_s(threshold=50)
arr = []
self.each_row.with_index do |row, pos|
next nil if pos > threshold && pos != self.length-1
arr.push({"" => @index[pos]}.merge(row.to_hash))
if pos == threshold
arr.push(@labels.reduce({"" => "..."}){|memo, label| memo[label] = "..."; memo})
end
end
Formatador.display_table(arr.select{|el| !(el.nil?)})
end

def select(&block)
return self.to_enum(:select) unless block_given?
rows = []
Expand Down
12 changes: 11 additions & 1 deletion lib/mikon/core/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def [](arg)
@data[pos]
end

def to_html(threshold=3)
def to_html(threshold=5)
html = "<table><tr><th></th><th>" + self.name.to_s + "</th></tr>"
@index.each.with_index do |index, pos|
next if pos > threshold && pos != self.length-1
Expand All @@ -57,6 +57,16 @@ def to_html(threshold=3)
html + "</table>"
end

def to_s(threshold=5)
arr = []
@index.each.with_index do |index, pos|
next nil if pos > threshold && pos != self.length-1
arr.push({"" => index, @name => @data[pos]})
arr.push({"" => "...", @name => "..."}) if pos == threshold
end
Formatador.display_table(arr.select{|el| !(el.nil?)})
end

def name(new_name=nil)
if new_name.nil?
@name
Expand Down
2 changes: 2 additions & 0 deletions mikon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_runtime_dependency "nmatrix", "~> 0.1.0.rc5"
spec.add_runtime_dependency "formatador", "~> 0.2.5"
spec.add_runtime_dependency "nyaplot", "~> 0.1.1"
spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
end

0 comments on commit 374892c

Please sign in to comment.