Class: Slobr::Slobr
- Inherits:
-
Object
- Object
- Slobr::Slobr
- Defined in:
- lib/slobr.rb
Instance Method Summary collapse
- #broji_slova(t = @text) ⇒ Object
-
#debug(txt = '') ⇒ Object
a = TextGraph.new({ :values => @hash.values, :labels => @hash.keys }) puts a.
- #debug? ⇒ Boolean
-
#initialize(text = nil) ⇒ Slobr
constructor
A new instance of Slobr.
- #ispis(put = false) ⇒ Object
- #text ⇒ Object
- #text=(text) ⇒ Object
Constructor Details
#initialize(text = nil) ⇒ Slobr
Returns a new instance of Slobr.
10 11 12 13 14 15 16 |
# File 'lib/slobr.rb', line 10 def initialize(text = nil) @text = text || (puts "Text je nil!"; exit) @debug = false @h = {} @regex = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #+"ćžpšđĆŽPŠĐ" end |
Instance Method Details
#broji_slova(t = @text) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/slobr.rb', line 18 def broji_slova(t = @text) t.each_char { |s| s = s.upcase if @regex.include? s @h[s]=0 if @h[s].nil? @h[s]+=1 end } end |
#debug(txt = '') ⇒ Object
a = TextGraph.new(
:values => @hash.values,
:labels => @hash.keys
) puts a
51 52 53 |
# File 'lib/slobr.rb', line 51 def debug(txt='') puts '[d] '+txt if debug? end |
#debug? ⇒ Boolean
55 56 57 |
# File 'lib/slobr.rb', line 55 def debug? !!@debug end |
#ispis(put = false) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/slobr.rb', line 36 def ispis(put = false) t = ["Slovo, Frekv."] @h.sort{|l,r| r[1]<=>l[1] }.each { |s,c| t << " %s: %i" % [s, c] } return t.join("\n") unless put put t.join("\n") end |
#text ⇒ Object
28 29 30 |
# File 'lib/slobr.rb', line 28 def text @text end |
#text=(text) ⇒ Object
32 33 34 |
# File 'lib/slobr.rb', line 32 def text=(text) @text = text end |