Class: Habaki::Values
Overview
Array of Values
Instance Method Summary collapse
-
#each_value(klass = nil, &block) ⇒ void
traverse values with optional class type.
- #read_from_katana(vals) ⇒ void private
-
#remove_value(value) ⇒ void
remove value taking care of operator in list.
- #string(format = Formatter::Base.new) ⇒ String
Methods inherited from NodeArray
Instance Method Details
#each_value(klass = nil, &block) ⇒ void
This method returns an undefined value.
traverse values with optional class type
7 8 9 10 11 |
# File 'lib/habaki/values.rb', line 7 def each_value(klass = nil, &block) each do |value| block.call value if !klass || value.is_a?(klass) end end |
#read_from_katana(vals) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
46 47 48 49 50 |
# File 'lib/habaki/values.rb', line 46 def read_from_katana(vals) vals.each do |val| push read_from_unit(val) end end |
#remove_value(value) ⇒ void
This method returns an undefined value.
remove value taking care of operator in list
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/habaki/values.rb', line 16 def remove_value(value) idx = index(value) prev_val = at(idx - 1) next_val = at(idx + 1) if prev_val&.is_a?(Operator) delete_at(idx) delete_at(idx - 1) elsif next_val&.is_a?(Operator) delete_at(idx + 1) delete_at(idx) else delete_at(idx) end end |
#string(format = Formatter::Base.new) ⇒ String
33 34 35 36 37 38 39 40 41 |
# File 'lib/habaki/values.rb', line 33 def string(format = Formatter::Base.new) str = "" each_cons(2) do |val| str += val[0].string(format) str += val[1].is_a?(Operator) || val[0].is_a?(Operator) ? "" : " " end str += last.string(format) if last str end |