Class: Boolio
- Inherits:
-
Object
- Object
- Boolio
- Defined in:
- lib/boolio.rb,
lib/boolio/version.rb
Constant Summary collapse
- URL =
"https://api.booleans.io/"- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#val ⇒ Object
Returns the value of attribute val.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy! ⇒ Object
-
#initialize(opts = {}) ⇒ Boolio
constructor
A new instance of Boolio.
- #to_s ⇒ Object
- #update(value = val) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Boolio
Returns a new instance of Boolio.
11 12 13 14 |
# File 'lib/boolio.rb', line 11 def initialize(opts = {}) @val = process_init_value(opts[:val]) @id = opts[:id] || post(@val)["id"] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/boolio.rb', line 6 def id @id end |
#val ⇒ Object
Returns the value of attribute val.
7 8 9 |
# File 'lib/boolio.rb', line 7 def val @val end |
Class Method Details
.fetch(id) ⇒ Object
32 33 34 35 36 |
# File 'lib/boolio.rb', line 32 def self.fetch(id) response = HTTP.get(URL + id) boolean = JSON.parse response.body Boolio.new(id: boolean["id"], val: boolean["val"]) end |
Instance Method Details
#destroy! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/boolio.rb', line 20 def destroy! return if frozen? response = delete if response.code == 200 @id = nil @val = nil freeze else raise "Could not destroy boolean: #{response.status}" end end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/boolio.rb', line 38 def to_s val end |
#update(value = val) ⇒ Object
16 17 18 |
# File 'lib/boolio.rb', line 16 def update(value = val) put(value) end |