Class: RandomOrg::Integer

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

Constant Summary collapse

ValidBases =
[2, 8, 10, 16]
@@url =
URI.parse("http://random.org/integers/")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min, max, base = 10) ⇒ Integer

Returns a new instance of Integer.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/random_org.rb', line 12

def initialize(min, max, base=10)
	@min = min.to_s
	@max = max.to_s
	@base = base.to_s
	@@url.query = "num=1&min=#{@min}&max=#{@max}&col=1&base=#{@base}&format=plain&rnd=new"
	
	begin
		res = Net::HTTP.get(@@url).chomp
		if @base.to_i == 16
			@value = res
		else
			@value = res.to_i
		end
	rescue Net::HTTPFatalError => e
		puts "Error: " + e
	end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



10
11
12
# File 'lib/random_org.rb', line 10

def base
  @base
end

#maxObject (readonly)

Returns the value of attribute max.



10
11
12
# File 'lib/random_org.rb', line 10

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



10
11
12
# File 'lib/random_org.rb', line 10

def min
  @min
end

#optsObject (readonly)

Returns the value of attribute opts.



10
11
12
# File 'lib/random_org.rb', line 10

def opts
  @opts
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/random_org.rb', line 10

def value
  @value
end