lib/extenso_pt.rb in extenso_pt-0.1.2 vs lib/extenso_pt.rb in extenso_pt-0.2.0

- old
+ new

@@ -19,24 +19,16 @@ def self.f6(k,b)o(k>0&&b>0?2:0)end def self.f7(u,b)o(u[2..-1].to_a.find{|v|v>0}.to_i>0&&u[0..1].inject(:+).to_i==0?3:u.count>0&&b==0?4:0)end def self.i(n,p)s=n%100;l((n>100?1:0)+n/100)+f1(n)+c(s/10)+f2(s)+z(p==1&&n==1?0:s<20?s:s%10)end def self.w(u,d)t=u.find{|v|v>0}.to_i+u[1..-1].to_a.find{|v|v>0}.to_i;f7(u,t+d)+f4(t)+f6(t,d)+i(d,0)+f5(d)end def self.r(g,j,p)t=j[p];p>=j.count*1?g:r(i(t,p)+h(t>0?t>1?8+p:p:0)+f3(p>0?j[p-1]:0)+g,j,p+1)end - def extenso(ms="EURO",cs="CÊNTIMO",mp=(a2=true;"EUROS"),cp=(a4=true;"CÊNTIMOS")) + def extenso(f={moeda:"EURO",fracao:"CÊNTIMO",moedap:"EUROS",fracaop:"CÊNTIMOS"}) n=(self.is_a?String)?self:'%.2f'%self - @@ms=ms;@@cs=cs - @@mp=(a2)?ms+"S":mp - @@cp=(a4)?cs+"S":cp + @@ms=f[:moeda]?f[:moeda]:"EURO";@@cs=f[:fracao]?f[:fracao]:"CÊNTIMO" + @@mp=f[:moedap]?f[:moedap]:@@ms+"S";@@cp=f[:fracaop]?f[:fracaop]:@@cs+"S" q=n[/^\d+/].to_s.reverse.scan(/\d{1,3}/).map{|i|i.reverse.to_i} q.count>8?"":ExtensoPt.r("",q,0)+ExtensoPt.w(q,(n[/\.\d*/].to_f*100).round) end end -class String - include ExtensoPt -end -class Float - include ExtensoPt -end -class Integer - include ExtensoPt -end - +class String; include ExtensoPt;end +class Float; include ExtensoPt;end +class Integer;include ExtensoPt;end