mixer 0.0.1

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.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
data/bin/mixer ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mixer'
4
+ puts Mixer.hi(ARGV[0])
data/lib/mixer.rb ADDED
@@ -0,0 +1,10 @@
1
+ class Mixer
2
+ def self.hi(language)
3
+ napis="{{{wow|now}|tram|xx}| zram} "
4
+ mix = Mixuj.new(napis)
5
+ puts mix.mixuj(napis)
6
+ puts mix.output
7
+ end
8
+ end
9
+
10
+ require 'mixer/mixuj'
@@ -0,0 +1,170 @@
1
+ #encoding: UTF-8
2
+
3
+ class Mixer::Mixuj
4
+ #private
5
+ attr_accessor :dl, :input, :output, :error, :dl_max, :dl_min
6
+ public
7
+ def initialize(string)
8
+ @input = string
9
+ @dl=string.size
10
+ @dl_max=string.size
11
+ @dl_min=string.size
12
+ end
13
+
14
+ def valid(string)
15
+
16
+ s1=string
17
+ il_zam=0
18
+ il_dom=0
19
+ il_zam2=0
20
+ il_dom2=0
21
+
22
+ il_zam=s1.count"{"
23
+ il_dom=s1.count"}"
24
+ il_zam2=s1.count"["
25
+ il_dom2=s1.count"]"
26
+
27
+ if s1.empty?
28
+ @error="Brak tekstu"
29
+ return false
30
+ end
31
+ if il_zam != il_dom
32
+ @error="Niezgodnosc w ilosci nawiasow { }"
33
+ return false
34
+ end
35
+ if il_zam2 != il_dom2
36
+ @error="Niezgodnosc w ilosci nawiasow [ ]"
37
+ return false
38
+ end
39
+ if il_zam==0 and il_zam2==0 and s1.include? "|"
40
+ @error="wystapilo | pomimmo bralu nawiasow [] lub {}"
41
+ return false
42
+ end
43
+ if s1.include? "{}"
44
+ @error="pusty { }"
45
+ return false
46
+ end
47
+ if s1.include? "[]"
48
+ @error="pusty [ ]"
49
+ return false
50
+ end
51
+ #if not s1.slice(/{*[^{]*}*\|.*{/).nil? #(/{[^{]+}+|.+{/
52
+ # puts s1.slice(/{*[^{]*}*\|.*{/)
53
+ # @error="wystapilo | przed po za {}"
54
+ # return false
55
+ #end
56
+
57
+ return true
58
+ end
59
+
60
+ def max_min(tab)
61
+ min=-1
62
+ max=-1
63
+ tab.each do |i|
64
+ if max==-1 or (i.length)>max
65
+ max=i.length
66
+
67
+ end
68
+ if min==-1 or (i.length)<min
69
+ min=i.length
70
+ end
71
+ end
72
+
73
+ return max,min
74
+ end
75
+
76
+ def mixuj(s1)
77
+
78
+ valid(s1)
79
+ if not valid(s1)
80
+ return error
81
+ else
82
+
83
+
84
+
85
+ # SPRAWDZANIE paragrafow
86
+ if s1.include? "\n\n"
87
+ tab_wyc=s1.split("\n\n")
88
+ tab_wyc.shuffle!
89
+ tab_wyc.each do |j|
90
+ j=j+"\n\n"
91
+ end
92
+ tab_wyc[tab_wyc.size-1].chomp!
93
+ s1=""
94
+ tab_wyc.each do |j|
95
+ s1=s1+j
96
+ end
97
+ end
98
+
99
+
100
+
101
+
102
+ # SPRAWDZANIE [ ]
103
+ until s1.slice(/\[.+\]/).nil?
104
+ wyc=s1.slice(/\[.+\]/)
105
+
106
+ @dl=dl-wyc.size
107
+ @dl_max=dl_max-wyc.size
108
+ @dl_min=dl_min-wyc.size
109
+ poz=s1.index(wyc)
110
+ s1.slice!(/\[.+\]/)
111
+ wyc=wyc[1..-2]
112
+
113
+
114
+ begin
115
+
116
+ tab_wyc=wyc.split("|")
117
+ tab_wyc.shuffle!
118
+ wyc=""
119
+ tab_wyc.each do |j|
120
+ wyc=wyc+j
121
+ end
122
+ @dl=dl+wyc.size
123
+ @dl_max=dl_max+wyc.size
124
+ @dl_min=dl_min+wyc.size
125
+ s1.insert(poz, wyc)
126
+
127
+ rescue
128
+ puts @error="Blad: #{$!}"
129
+ end
130
+ end
131
+
132
+
133
+
134
+
135
+ # SPRAWDZANIE { }
136
+ until s1.slice(/{[^}]+}/).nil?
137
+ wyc=s1.slice(/{[^{.+}]+}/)
138
+ @dl=dl-wyc.size
139
+ @dl_max=dl_max-wyc.size
140
+ @dl_min=dl_min-wyc.size
141
+ poz=s1.index(wyc)
142
+ s1.slice!(/{[^{.+}]+}/)
143
+ wyc=wyc[1..-2]
144
+
145
+
146
+ begin
147
+ if wyc[-1, 1]=="|"
148
+ tab_wyc=wyc.split("|")
149
+ tab_wyc[tab_wyc.size]=""
150
+ else
151
+ tab_wyc=wyc.split("|")
152
+ end
153
+ tmp_min,tmp_max = max_min(tab_wyc)
154
+ wyc=tab_wyc[rand(tab_wyc.size())] #random synonimu
155
+ @dl=dl+wyc.size
156
+ @dl_max=dl_max+tmp_max
157
+ @dl_min=dl_min+tmp_min
158
+ s1.insert(poz, wyc)
159
+ rescue
160
+ puts @error="Blad: #{$!}"
161
+ end
162
+ end
163
+ wynik=""
164
+ wynik=s1
165
+ @output=wynik
166
+ return output #,dl,dl_max,dl_min
167
+
168
+ end
169
+ end
170
+ end
data/test/test_hola.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'hola'
3
+
4
+ class HolaTest < Test::Unit::TestCase
5
+ def test_english_hello
6
+ assert_equal "hello world", Hola.hi("english")
7
+ end
8
+
9
+ def test_any_hello
10
+ assert_equal "hello world", Hola.hi("ruby")
11
+ end
12
+
13
+ def test_spanish_hello
14
+ assert_equal "hola mundo", Hola.hi("spanish")
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mixer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lukas Szczesiak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Mixer
15
+ email: lukas.szczesiak@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Rakefile
21
+ - lib/mixer.rb
22
+ - lib/mixer/mixuj.rb
23
+ - bin/mixer
24
+ - test/test_hola.rb
25
+ homepage: http://rubygems.org/gems/mixer
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.24
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Mixer!
49
+ test_files:
50
+ - test/test_hola.rb