Class: CSVPlusPlus::Language::Entities::Entity
- Inherits:
-
Object
- Object
- CSVPlusPlus::Language::Entities::Entity
- Defined in:
- lib/csv_plus_plus/language/entities/entity.rb
Overview
A basic building block of the abstract syntax tree (AST)
Direct Known Subclasses
Boolean, CellReference, EntityWithArguments, Number, RuntimeValue, String, Variable
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
.
-
#initialize(type, id: nil) ⇒ Entity
constructor
initialize.
-
#method_missing(method_name, *_arguments) ⇒ Object
Respond to predicates that correspond to types like #boolean?, #string?, etc.
-
#respond_to_missing?(method_name, *_arguments) ⇒ Boolean
support predicates by type.
Constructor Details
#initialize(type, id: nil) ⇒ Entity
initialize
13 14 15 16 |
# File 'lib/csv_plus_plus/language/entities/entity.rb', line 13 def initialize(type, id: nil) @type = type.to_sym @id = id.downcase.to_sym if id end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_arguments) ⇒ Object
Respond to predicates that correspond to types like #boolean?, #string?, etc
24 25 26 27 28 29 30 31 |
# File 'lib/csv_plus_plus/language/entities/entity.rb', line 24 def method_missing(method_name, *_arguments) if method_name =~ /^(\w+)\?$/ t = ::Regexp.last_match(1) a_type?(t) && @type == t.to_sym else super end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/csv_plus_plus/language/entities/entity.rb', line 10 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/csv_plus_plus/language/entities/entity.rb', line 10 def type @type end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/csv_plus_plus/language/entities/entity.rb', line 19 def ==(other) self.class == other.class && @type == other.type && @id == other.id end |
#respond_to_missing?(method_name, *_arguments) ⇒ Boolean
support predicates by type
34 35 36 |
# File 'lib/csv_plus_plus/language/entities/entity.rb', line 34 def respond_to_missing?(method_name, *_arguments) (method_name =~ /^(\w+)\?$/ && a_type?(::Regexp.last_match(1))) || super end |