Class: Argumenta::Objects::Proposition
- Inherits:
-
Object
- Object
- Argumenta::Objects::Proposition
- Defined in:
- lib/argumenta/objects/proposition.rb
Overview
A proposition models an assertion as a string of text. It has an associated object record and SHA-1 hash. The object record is similar to Git’s blob. The SHA-1 identifies the proposition.
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
-
.validate(object) ⇒ Object
Validates an object as a proposition.
Instance Method Summary collapse
-
#initialize(text) ⇒ Proposition
constructor
Initializes a new proposition.
-
#record ⇒ Object
Gets the proposition’s object record.
-
#sha1 ⇒ Object
Gets the proposition’s SHA-1.
-
#valid? ⇒ Boolean
Checks whether proposition is valid.
-
#validate ⇒ Object
Validates the proposition.
Constructor Details
#initialize(text) ⇒ Proposition
Initializes a new proposition.
text = "My proposition!"
proposition = Proposition.new text
16 17 18 |
# File 'lib/argumenta/objects/proposition.rb', line 16 def initialize(text) @text = text end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/argumenta/objects/proposition.rb', line 9 def error @error end |
#text ⇒ Object
Returns the value of attribute text.
9 10 11 |
# File 'lib/argumenta/objects/proposition.rb', line 9 def text @text end |
Class Method Details
.validate(object) ⇒ Object
Validates an object as a proposition.
valid = Proposition.validate object
41 42 43 44 45 46 |
# File 'lib/argumenta/objects/proposition.rb', line 41 def self.validate(object) unless object.is_a? self raise ValidationError "Object must be a proposition." end object.validate end |
Instance Method Details
#record ⇒ Object
Gets the proposition’s object record.
record = proposition.record
24 25 26 |
# File 'lib/argumenta/objects/proposition.rb', line 24 def record "proposition " + @text end |
#sha1 ⇒ Object
Gets the proposition’s SHA-1.
sha1 = proposition.sha1
32 33 34 |
# File 'lib/argumenta/objects/proposition.rb', line 32 def sha1 Digest::SHA1.hexdigest self.record end |
#valid? ⇒ Boolean
Checks whether proposition is valid.
valid = proposition.valid?
74 75 76 77 78 79 80 81 82 |
# File 'lib/argumenta/objects/proposition.rb', line 74 def valid? begin self.validate return true rescue ValidationError => err @error = err return false end end |
#validate ⇒ Object
Validates the proposition.
begin
proposition.validate
rescue Argumenta::ValidationError => err
puts "Validation failed: ", err.
end
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/argumenta/objects/proposition.rb', line 57 def validate unless @text.is_a? String raise ValidationError, "Proposition text must be a string." end unless @text.length > 0 and text.match /\S+/ raise ValidationError, "Proposition text must not be empty." end unless @text.length <= 240 raise ValidationError, "Proposition text must be 240 characters or less." end end |