Class: Slobr::Slobr

Inherits:
Object
  • Object
show all
Defined in:
lib/slobr.rb

Instance Method Summary collapse

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

Returns:

  • (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

#textObject



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