Class: DTRCore::State
Overview
Represents a state in a DTR file.
Instance Attribute Summary collapse
-
#initial_value ⇒ Object
readonly
Returns the value of attribute initial_value.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, type, initial_value) ⇒ State
constructor
A new instance of State.
- #sanitize ⇒ Object
Methods included from Common
#clean_name, #first_match_for_content, #split_strip_select, #strip_and_remove_quotes
Constructor Details
#initialize(name, type, initial_value) ⇒ State
Returns a new instance of State.
12 13 14 15 16 |
# File 'lib/dtr_core/state.rb', line 12 def initialize(name, type, initial_value) @name = name @type = type @initial_value = initial_value end |
Instance Attribute Details
#initial_value ⇒ Object (readonly)
Returns the value of attribute initial_value.
10 11 12 |
# File 'lib/dtr_core/state.rb', line 10 def initial_value @initial_value end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/dtr_core/state.rb', line 10 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/dtr_core/state.rb', line 10 def type @type end |
Class Method Details
.from_definition(definition) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dtr_core/state.rb', line 22 def self.from_definition(definition) not_yet_cleaned_name = definition[/^\[([^\]]+)\]/, 1] type = definition[/Type:\s*(\w+)/, 1] initial_value = DTRCore::TypeValidator.new(type, definition[/Initial Value:\s*(.+)/, 1]) .validate_then_coerce_initial_value! state_object = new(not_yet_cleaned_name, type, initial_value) state_object.sanitize state_object end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 40 41 |
# File 'lib/dtr_core/state.rb', line 37 def ==(other) name == other.name && type == other.type && initial_value == other.initial_value end |
#sanitize ⇒ Object
18 19 20 |
# File 'lib/dtr_core/state.rb', line 18 def sanitize @name = clean_name @name end |