haskii 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0095132799344c995787e697cb823d18e0e86a83
4
- data.tar.gz: dca8fca7ad2f4b13616181a3f4da45a135205c4f
3
+ metadata.gz: 7ea4f2674f1fb601480a987bc91e3e80d1e35356
4
+ data.tar.gz: bf1b4588be1c6e3cb88d33ec8b42fb705abc1a8e
5
5
  SHA512:
6
- metadata.gz: 542acdc35cbf3a4c3ad4c18348b66d4d916d836d8b378391e11a23612a54d551f532ede8ab4bfc18f7f1696b7591ee7a7479c8c1c3a6b21167c35ea4cd1ed2c4
7
- data.tar.gz: 5a5c655cd6500920f9b74f32d21b9df25b463905db959468831a045641baa1b865a0019335a4f0df01e9f06b3acb24cfa6f0e298f297655ed32e03dc44cd6320
6
+ metadata.gz: 60609f6d6cd41f2f05e3ab5793c999307f45d08b2b8a0df12564154e48d6147acdfb252b2746d5259949b74345af98cf2c45a6300993f93309b57213a1b9aa9e
7
+ data.tar.gz: 885901c0c0dcab7cfdc7020e7f1da1a14670aa02f5ab8e1f0833c7fe73017fa42b83011ce5383eee664100a4a22e1c4ded0531e0f82cf54fa8319815c9e860df
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Haskii
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/haskii`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
@@ -35,7 +31,7 @@ Your happy bar chart:
35
31
  ******* *****
36
32
  **************
37
33
 
38
- $haskii bar --emoji 🍀 1 1 2 3 5 2
34
+ $ haskii bar --emoji 🍀 1 1 2 3 5 2
39
35
  Your happy bar chart:
40
36
 
41
37
  🍀
@@ -43,6 +39,10 @@ Your happy bar chart:
43
39
  🍀🍀
44
40
  🍀🍀🍀🍀
45
41
  🍀🍀🍀🍀🍀🍀
42
+
43
+ $ haskii bar --emoji 🍒 --output chart.html 2 4 6 8 6 4 2 1 6 5 4 3 2 1
44
+ Your happy bar chart is in "chart.html"
45
+ Terminal still rules :P #igor
46
46
  ```
47
47
 
48
48
 
@@ -54,7 +54,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
54
54
 
55
55
  ## Contributing
56
56
 
57
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/haskii.
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mimimalizam/haskii.
58
58
 
59
59
 
60
60
  ## License
data/chart.html ADDED
@@ -0,0 +1 @@
1
+ <table><tr><td> </td><td> </td><td> </td><td>🍒</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td> </td><td> </td><td> </td><td>🍒</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td> </td><td> </td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td><td> </td><td> </td><td>🍒</td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td> </td><td> </td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td><td> </td><td> </td><td>🍒</td><td>🍒</td><td> </td><td> </td><td> </td><td> </td></tr><tr><td> </td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td><td> </td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td><td> </td><td> </td></tr><tr><td> </td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td><td> </td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td><td> </td></tr><tr><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td> </td></tr><tr><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td><td>🍒</td></tr></table>
@@ -6,7 +6,7 @@ module Haskii
6
6
  end
7
7
 
8
8
  def render
9
- @matrix.map { |line| line.join("") }
9
+ raise NotImplementedError, "render method is not implemented"
10
10
  end
11
11
 
12
12
  end
data/lib/haskii/cli.rb CHANGED
@@ -20,18 +20,23 @@ module Haskii
20
20
  \x5>🍒🍒
21
21
  \x5>🍒🍒
22
22
  \x5>🍒🍒🍒
23
+
24
+ If you specify --output option, haskii bar will save surprise chart in
25
+ a html file
26
+
27
+ > $ haskii bar --emoji 🍒 --output chart.html 2 4 6 8 6 4 2 1 6 5 4 3 2 1
28
+ \x5> Your happy bar chart is in "chart.html".
29
+ \x5> Terminal still rules :P #igor
23
30
  LONGDESC
31
+
32
+ option :output
24
33
  option :emoji, :default => "*"
25
34
  def bar(*frequences)
26
35
  @frequences = frequences
36
+ @output_file = options[:output]
37
+ @emoji = options[:emoji]
27
38
 
28
- if it_can_be_charted?
29
- result = Haskii::BarChart.new(@frequences, options[:emoji]).render
30
- puts "Your happy bar chart:\n\n"
31
- puts result
32
- else
33
- puts "Nothing to see here, please spare some numbers without letters. Tnx"
34
- end
39
+ it_can_be_charted ? create_output : ask_for_numbers
35
40
  end
36
41
 
37
42
  desc "version", "Prints the haskii version info"
@@ -42,13 +47,39 @@ module Haskii
42
47
 
43
48
  private
44
49
 
50
+ def it_can_be_charted
51
+ ( not @frequences.empty? ) && (convert_to_integer.min > 0)
52
+ end
53
+
54
+ def create_output
55
+ @output_file ? render_html_chart : render_terminal_chart
56
+ end
57
+
58
+ def ask_for_numbers
59
+ puts "Nothing to see here, please spare some numbers without letters. Tnx"
60
+ end
61
+
62
+ def render_html_chart
63
+ result = Haskii::HtmlChart.new(@frequences, @emoji).render
64
+ create_html(result)
65
+ end
66
+
67
+ def render_terminal_chart
68
+ result = Haskii::TerminalChart.new(@frequences, @emoji).render
69
+ puts "Your happy bar chart:\n\n"
70
+ puts result
71
+ end
72
+
45
73
  def convert_to_integer
46
- @frequences.map! { |i| i.to_i }
74
+ @frequences.map! { |i| i.to_i }
47
75
  end
48
76
 
49
- def it_can_be_charted?
50
- ( not @frequences.empty? ) && (convert_to_integer.min > 0)
77
+ def create_html(result)
78
+ html_file = File.new(@output_file, "w+")
79
+ html_file.puts result
80
+ html_file.close
81
+ puts "Your happy bar chart is in \"#{@output_file}\"\nTerminal still rules :P #igor"
51
82
  end
52
- end
53
83
 
84
+ end
54
85
  end
@@ -0,0 +1,23 @@
1
+ module Haskii
2
+ class HtmlChart < BarChart
3
+
4
+ def render
5
+ cells = @matrix.map { |row| add_tag('tr', transform_to_cells(row)) }
6
+ .join
7
+
8
+ add_tag('table', cells)
9
+ end
10
+
11
+ private
12
+
13
+ def transform_to_cells(row)
14
+ row.map { |node| add_tag('td', node) }
15
+ .join
16
+ end
17
+
18
+ def add_tag(tag, string)
19
+ "<#{tag}>#{string}</#{tag}>"
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Haskii
2
+ class TerminalChart < BarChart
3
+
4
+ def render
5
+ @matrix.map { |line| line.join("") }
6
+ end
7
+
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Haskii
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haskii
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Milana
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-04 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,12 +96,15 @@ files:
96
96
  - Rakefile
97
97
  - bin/console
98
98
  - bin/setup
99
+ - chart.html
99
100
  - exe/haskii
100
101
  - haskii.gemspec
101
102
  - lib/haskii.rb
102
103
  - lib/haskii/bar_chart.rb
103
104
  - lib/haskii/cli.rb
105
+ - lib/haskii/html_chart.rb
104
106
  - lib/haskii/mimi_matrix.rb
107
+ - lib/haskii/terminal_chart.rb
105
108
  - lib/haskii/version.rb
106
109
  homepage: https://rubygems.org/gems/haskii
107
110
  licenses: