Class: RandomOrg::Integer
- Inherits:
-
Object
- Object
- RandomOrg::Integer
- 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
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(min, max, base = 10) ⇒ Integer
constructor
A new instance of Integer.
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
#base ⇒ Object (readonly)
Returns the value of attribute base.
10 11 12 |
# File 'lib/random_org.rb', line 10 def base @base end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
10 11 12 |
# File 'lib/random_org.rb', line 10 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
10 11 12 |
# File 'lib/random_org.rb', line 10 def min @min end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
10 11 12 |
# File 'lib/random_org.rb', line 10 def opts @opts end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/random_org.rb', line 10 def value @value end |