Class: Contraction::Parser::TypedLine
- Inherits:
-
Object
- Object
- Contraction::Parser::TypedLine
- Defined in:
- lib/parser/lines.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#contract ⇒ Object
Returns the value of attribute contract.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #contract_message(value = nil, method_name = nil) ⇒ Object
- #evaluate_in_context(context, method_name, value) ⇒ Object
-
#initialize(args = {}) ⇒ TypedLine
constructor
A new instance of TypedLine.
- #parse_type ⇒ Object
- #valid?(*value) ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ TypedLine
Returns a new instance of TypedLine.
10 11 12 13 14 15 |
# File 'lib/parser/lines.rb', line 10 def initialize(args={}) @type = args[:type] @contract = args[:contract] = args[:message] parse_type end |
Instance Attribute Details
#contract ⇒ Object
Returns the value of attribute contract.
7 8 9 |
# File 'lib/parser/lines.rb', line 7 def contract @contract end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/parser/lines.rb', line 7 def end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/parser/lines.rb', line 7 def type @type end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
7 8 9 |
# File 'lib/parser/lines.rb', line 7 def types @types end |
Instance Method Details
#contract_message(value = nil, method_name = nil) ⇒ Object
36 37 38 |
# File 'lib/parser/lines.rb', line 36 def (value=nil, method_name=nil) raise 'Not Implemented' end |
#evaluate_in_context(context, method_name, value) ⇒ Object
31 32 33 34 |
# File 'lib/parser/lines.rb', line 31 def evaluate_in_context(context, method_name, value) return if !contract || contract.to_s.strip == '' raise (value, method_name) unless eval(contract, context) end |
#parse_type ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/parser/lines.rb', line 17 def parse_type parts = type.split(/(\>|\}|\)),/) @types = [] parts.each do |part| @types << Type.new(part) end end |
#valid?(*value) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/parser/lines.rb', line 25 def valid?(*value) @types.each_with_index.all? do |t, i| t.check(value[i]) end end |