Class: Plt::Config
- Inherits:
-
Object
- Object
- Plt::Config
- Defined in:
- lib/plt/config.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #groups ⇒ Object
-
#initialize(name, elements) ⇒ Config
constructor
A new instance of Config.
- #open! ⇒ Object
- #save_to(path) ⇒ Object
- #save_to_tmp ⇒ Object
- #signals ⇒ Object
- #to_plt ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, elements) ⇒ Config
Returns a new instance of Config.
9 10 11 12 |
# File 'lib/plt/config.rb', line 9 def initialize(name, elements) @name = name @elements = elements end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
8 9 10 |
# File 'lib/plt/config.rb', line 8 def elements @elements end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/plt/config.rb', line 8 def name @name end |
Class Method Details
.from_file(filepath) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/plt/config.rb', line 14 def self.from_file(filepath) elements = [] group = nil File.readlines(filepath).each do |line| line = line.sub(/^~ /, "") # Remove disabled comments, group has info already case line in %r{^//BEGIN_GROUP} fail "Invalid GROUP definition: #{line} (still inside previous definition)" if group group = Group.from_line(line) in %r{^//END_GROUP} fail "Cannot end GROUP definition (none open)" unless group elements << group group = nil in %r{^\w+} if group group.signals << Signal.from_line(line) else elements << Signal.from_line(line) end in %r{^+} # ignore, expression from previous signal end end new(File.basename(filepath), elements) end |
Instance Method Details
#groups ⇒ Object
40 41 42 |
# File 'lib/plt/config.rb', line 40 def groups elements.select { _1.is_a?(Group) } end |
#open! ⇒ Object
62 63 64 65 |
# File 'lib/plt/config.rb', line 62 def open! spawn(UNIVIEW_PATH, "/n", save_to_tmp, out: "/dev/null", err: "/dev/null") .then { Process.detach(_1) } end |
#save_to(path) ⇒ Object
53 54 55 56 |
# File 'lib/plt/config.rb', line 53 def save_to(path) File.join(path, name) .tap { File.write(_1, to_plt) } end |
#save_to_tmp ⇒ Object
58 59 60 |
# File 'lib/plt/config.rb', line 58 def save_to_tmp `wslpath -w #{save_to(TMP_PATH)}` end |
#signals ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/plt/config.rb', line 44 def signals elements.flat_map do case _1 in Group then _1.signals in Signal then _1 end end end |
#to_plt ⇒ Object
72 73 74 |
# File 'lib/plt/config.rb', line 72 def to_plt elements.map(&:to_plt).join("\n") end |
#to_s ⇒ Object
67 68 69 70 |
# File 'lib/plt/config.rb', line 67 def to_s "#{name}:\n" + elements.map(&:to_s).join("\n") end |