Class: TextFSM::Field
- Inherits:
-
Object
- Object
- TextFSM::Field
- Defined in:
- lib/textfsm/field.rb
Instance Attribute Summary collapse
-
#capture_source ⇒ Object
readonly
Returns the value of attribute capture_source.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#option_names ⇒ Object
readonly
Returns the value of attribute option_names.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #assign(value) ⇒ Object
- #clear ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(line, parser:, options: Options::BUILTINS) ⇒ Field
constructor
A new instance of Field.
- #option?(name) ⇒ Boolean
- #prepare_record ⇒ Object
- #reset ⇒ Object
- #to_s ⇒ Object
- #visible? ⇒ Boolean
Constructor Details
#initialize(line, parser:, options: Options::BUILTINS) ⇒ Field
Returns a new instance of Field.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/textfsm/field.rb', line 14 def initialize(line, parser:, options: Options::BUILTINS) @parser = parser parse_declaration(line) @pattern = Pattern.new(@source) @capture_source = "(?P<#{@name}>#{@source[1..]}".freeze @options = @option_names.map do |name| .fetch(name) { raise TemplateError, "Unknown option #{name.inspect}" }.new(self) end.freeze @options.each(&:after_initialize) end |
Instance Attribute Details
#capture_source ⇒ Object (readonly)
Returns the value of attribute capture_source.
11 12 13 |
# File 'lib/textfsm/field.rb', line 11 def capture_source @capture_source end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/textfsm/field.rb', line 11 def name @name end |
#option_names ⇒ Object (readonly)
Returns the value of attribute option_names.
11 12 13 |
# File 'lib/textfsm/field.rb', line 11 def option_names @option_names end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
11 12 13 |
# File 'lib/textfsm/field.rb', line 11 def parser @parser end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
11 12 13 |
# File 'lib/textfsm/field.rb', line 11 def pattern @pattern end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
11 12 13 |
# File 'lib/textfsm/field.rb', line 11 def source @source end |
#value ⇒ Object
Returns the value of attribute value.
12 13 14 |
# File 'lib/textfsm/field.rb', line 12 def value @value end |
Instance Method Details
#assign(value) ⇒ Object
37 38 39 40 |
# File 'lib/textfsm/field.rb', line 37 def assign(value) @value = value @options.each(&:after_assign) end |
#clear ⇒ Object
42 43 44 45 |
# File 'lib/textfsm/field.rb', line 42 def clear @value = nil @options.each(&:after_clear) end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/textfsm/field.rb', line 33 def empty? !@value || (@value.respond_to?(:empty?) && @value.empty?) end |
#option?(name) ⇒ Boolean
25 26 27 |
# File 'lib/textfsm/field.rb', line 25 def option?(name) @option_names.include?(name) end |
#prepare_record ⇒ Object
52 53 54 |
# File 'lib/textfsm/field.rb', line 52 def prepare_record @options.each(&:before_record) end |
#reset ⇒ Object
47 48 49 50 |
# File 'lib/textfsm/field.rb', line 47 def reset @value = nil @options.each(&:after_reset) end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/textfsm/field.rb', line 56 def to_s ["Value", (@option_names.join(",") unless @option_names.empty?), @name, @source].compact.join(" ") end |
#visible? ⇒ Boolean
29 30 31 |
# File 'lib/textfsm/field.rb', line 29 def visible? @options.all?(&:visible?) end |